"I have hesitated on gay marriage in part because I thought that civil unions would be sufficient," Obama said in an interview with ABC at the White House.
He added that, "I was sensitive to the fact that for a lot of people the word 'marriage' was something that invokes very powerful traditions, religious beliefs and so forth."
Now, he said, "it is important for me personally to go ahead and affirm that same-sex couples should be able to get married."
Obama's announcement cheered gay rights groups who have long urged him to support gay marriage. It also opened up a new area of disagreement with Republican presidential candidate Mitt Romney, who opposes gay marriage.
Polling suggests the nation is evenly divided on the issue.
Obama spoke about his support for gay marriage in deeply personal terms, saying his young daughters, Malia and Sasha, have friends whose parents are same-sex couples.
"Malia and Sasha, it wouldn't dawn on them that somehow their friends' parents would be treated different," Obama said. "It doesn't make sense to them and frankly, that's the kind of thing that prompts a change in perspective."
Obama said his wife Michelle Obama was also involved in his decision and joins him in supporting gay marriage.
"In the end the values that I care most deeply about and she cares most deeply about is how we treat other people," he said.
Acknowledging that his support for same-sex marriage may rankle religious conservatives, Obama said he thinks about his faith in part through the prism of the Golden Rule - treating others the way you would want to be treated.
"That's what we try to impart to our kids and that's what motivates me as president and I figure the most consistent I can be in being true to those precepts, the better I'll be as a as a dad and a husband and hopefully the better I'll be as president," Obama said.