President's comments may force Republican rival Romney into more conservative standpoint as he woos independent voters.
Obama supports same-sex marriage
The timing left some scratching their heads. Less than six months before Americans decide whether Mr Obama will serve a second term, his statement that it is his "personal belief that same-sex couples should be allowed to marry" cannot be divorced from the political context.
He has taken a clear position that his administration supports equal rights for homosexual, bisexual and transgender citizens.
It is an issue Mr Obama's liberal base, so enthused by his candidacy in 2008 but often disappointed with his record since assuming office, can rally around.
But he has done so at a time when there is no chance to affect national legislation. Most members of Congress oppose gay marriage.
Mr Obama's remarks in a television interview broadcast on Wednesday night has sparked a polarising debate.
In every state where a referendum on the issue has been held, voters have outlawed same-sex unions.
On Tuesday, North Carolina, a crucial swing state in November's election and the site of this summer's Democratic Party convention, became the 31st state to ban same-sex marriage.
But a Washington Post-ABC News poll in March found 52 per cent of Americans support legalising gay marriage, and 43 per cent oppose it.
Democrats overwhelmingly supported gay marriage, 64 to 32 per cent. Independents endorse it 54 to 42 per cent.
Republicans opposed it, 57 to 39 per cent.
Among African-Americans and Latinos, critical constituencies for Mr Obama, the issue is controversial. The Post/ABC poll showed that 55 per cent of African-Americans oppose same-sex marriage rights and 42 per cent are in favour.
But the Obama campaign may well calculate that while unpopular, his position will not hurt him in November, with a community that was solidly behind the election of the first African-American president.
Democratic strategists may see an advantage in putting an issue on the table that will force Mr Obama's probable rival, the former Massachusetts governor Mitt Romney, to take a conservative position just as he is trying to reach out to independent voters.
He will also have to avoid accusations of flip-flopping. The Obama campaign will be keen to point out that in 1994, when Mr Romney ran and lost against Democrat Ted Kennedy for Massachusetts senator, he touted his support for certain gay-rights positions, although that did not include same-sex marriage.
Mr Romney seemed aware of the danger on Wednesday when reacting to Mr Obama's remarks.
While he voiced his opposition to same-sex marriage - "My view is that marriage itself is between a man and a woman" - he also said he believed states should make decisions about the legal rights of same-sex couples.
The issue is contentious in American voters.
Mr Romney yesterday issued a statement denying a Washington Post report that suggested he bullied a gay classmate in high school.
He apologised to anyone he may have offended by what he called "high jinks and pranks".
For now, the issue will play out along the usual lines.
Liberal groups have rallied to Mr Obama's side. Rea Carey, executive director of the National Gay and Lesbian Task Force, hailed his remarks as a "great day" for the country.
Ralph Reed, director of the conservative Faith and Freedom Coalition, said the remarks showed Mr Obama was "out of touch" with American values and described them as an "unanticipated gift to the Romney campaign".
Mr Obama's remarks also sparked global reaction.
Ibrahim Ali, an independent member of Malaysia's parliament and leader of a rights group for the country's majority Malay Muslims, said he is worried what effect this would have in his country, where anti-homosexual legislation is on the books.
"They can practise this in America if they want, since it's their right, but we are still very concerned because whatever America practises it often wants other countries to follow suit," Mr Ali said.
The concern was echoed in Cameroon.
"When you think that the USA is the most powerful country in the world, then you can expect other countries will want to toe the line," said Dovan Bogning, a cartoonist at Le Popli newspaper.
"What will homosexual marriages positively contribute to humanity?"
* With additional reporting by the Associated Press