"I've just concluded that for me personally, it is important for me to go ahead and affirm that I think same-sex couples should be able to get married," Obama said in an hastily arranged interview with ABC News.
The interview came three days after Vice-President Joe Biden threw his own full support behind same-sex matrimony, a divisive issue that's now widely regarded as a modern-day civil rights battle.
White House aides say Biden's remarks expedited the president's announcement, one he'd planned to make anyway before the Democratic National Convention this summer.
Obama said his previously "evolving" position has changed over the years as he's "talked to friends and family and neighbours, when I think about members of my own staff who are in incredibly committed monogamous relationships, same-sex relationships."
He also mentioned those serving in the military who are "fighting on my behalf and yet feel constrained, even now that 'Don't Ask Don't Tell' is gone, because they are not able to commit themselves in a marriage."
Obama's wife Michelle also influenced his decision, he added.
"This is something that, you know, we've talked about over the years ... and she feels the same way that I do," Obama said. "In the end the values that I care most deeply about and she cares most deeply about is how we treat other people."
The fact that his young daughters have friends whose parents are same-sex couples also weighed heavily on him, he said.
"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."
Liberals rejoiced in the news.
"This is a historic day," Justin Ruben, executive director of MoveOn.org, a progressive advocacy group, said in a statement. "The president's support for marriage equality is great news that's likely to energize progressive activists across the country."
Michael Keegan, president of People For The American Way, said the announcement has restored the faith of liberals who believed in Obama.
"For thousands of supporters who donated, canvassed and phone-banked to help elect Barack Obama in 2008, this is a powerful reminder of why we felt so passionately about this president in the first place," he said.
The ABC interview, conducted by Robin Roberts, was the most hotly anticipated event of the day in the U.S. capital, with the White House press corps waiting with bated breath for the network to publish details of the conversation.
Political blogs, Twitter and the websites of myriad news outlets lit up with predictions about what the president might say.
The issue has long represented a pickle for Obama.
The president needs to take crucial swing states if he's to win re-election on Nov. 6. And on Tuesday, North Carolina voted overwhelmingly to strengthen its same-sex marriage ban in a state referendum; another swing state, Colorado, also killed a legislative measure that would allow same-sex matrimony.
The president narrowly won North Carolina in 2008, but took Colorado more handily. He said Tuesday night he was "disappointed" with the vote in North Carolina.
Some Democratic strategists feared other crucial swing states, like Virginia, could become question marks for Obama if he backed same-sex marriage. The White House apparently threw caution to the wind on those concerns amid a series of new polls that suggest increasing numbers of Americans have no problem with same-sex marriage.
Obama's new position came after years of doing a tricky dance on the issue thanks to some of his core constituents.
The young Americans who voted for him en masse in 2008 strongly support same-sex marriage. The African-Americans who also voted for him en masse in 2008 strongly oppose it.
He'll need the votes of both groups if he's to win re-election. And he'll also need the votes of another key constituency: gays.
The president has previously said his position on same-sex marriage is "evolving."
"I struggle with this," he said in 2010.
"I have friends, I have people who work for me who are in powerful, strong, long-lasting gay or lesbian unions. And they are extraordinary people. And this is something that means a lot to them and they care deeply about."
Recent polls suggest the issue is not nearly as divisive as it used to be.
A Gallup survey released this week found 50 per cent of adults are in favour of same-sex marriage. Democrats, at 65 per cent, and the crucial independent voters, at 57 per cent, support legal recognition of same-sex marriages, while 74 per cent of Republicans believe such unions should be illegal.
Republican front-runner Mitt Romney, meantime, has long been against same-sex marriage. He reiterated his opposition during a campaign stop in Oklahoma City on Wednesday.
"I believe marriage is a relationship between a man and a woman," he said when asked about the Obama interview.
"That's my own preference. I know other people have different views. This is a very tender and sensitive topic, as are many social issues, but I have the same views I've had since running for office."
Reince Priebus, head of the Republican National Committee, accused Obama of politicking and praised Romney's unwavering opposition to same-sex marriage.
"While President Obama has played politics on this issue, the Republican party and our presumptive nominee Mitt Romney have been clear. We support maintaining marriage between one man and one woman and would oppose any attempts to change that," he said in a statement.
Obama, meantime, said he was guided by the so-called Golden Rule — treating others the way you'd hope 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 dad and a husband, and hopefully the better I'll be as president."