"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 interview with ABC's Robin Roberts.
Obama's comments marked the first time a U.S. president had publicly expressed support for gay marriage, and his position was hailed by Democrats, gay rights groups and others as a benchmark for civil rights in the United States.
"This is a major turning point in the history of American civil rights" said New York Mayor Michael Bloomberg, an independent whose city is in one of six states that allow same-sex marriage.
Others, including Republican activists and conservative Christian leaders, criticized Obama's stance and called it a huge political risk on a divisive issue.
Noting that 29 states have approved bans on same-sex marriage, they said Obama's announcement could help his Republican opponent in the November 6 election, Mitt Romney, consolidate support among evangelical Christians who, like Romney, oppose gay marriage.
"Today's announcement ensures that marriage will again be a major issue in the presidential election," said Tony Perkins, a prominent evangelical leader and president of the Family Research Council, a conservative Christian group. "The president has provided a clear contrast between him and ... Mitt Romney."
Romney, campaigning in Oklahoma City, said he believes "marriage is a relationship between a man and a woman." He has said he supports hospital visitation rights and other domestic partnership benefits for gay and lesbian couples.
Political analysts saw Obama's move as a calculated risk at a time when polls indicate that a slight majority of Americans now support legally recognizing gay marriages.
"It is not without political risk," Democratic strategist Julian Epstein said on MSNBC. "Polls show that nearly every segment of the population" is moving toward acceptance of gay marriage, but "Republicans certainly will try to use it as a wedge in the African American community and with non-college educated white voters," key voting blocs in which many people oppose gay marriage.
FIRST LADY, DAUGHTERS INFLUENCED DECISION
Obama's comments came three days after Vice President Joe Biden said in a television interview that he was comfortable with gay marriage.
Senior administration officials indicated that Obama - who had walked a fine, politically sensitive line in supporting gay rights but not gay marriage - had planned to announce his support for such marriages before the Democratic National Convention in September.
The officials acknowledged that Biden's comments had moved up that timetable and said the president was not upset at Biden over his remarks.
During the ABC interview, Obama described his views as personal and said he still believed that individual U.S. states should be able to decide on the issue for themselves.
Obama, who ended the "Don't Ask, Don't Tell" policy that prevented gays from serving openly in the U.S. military, said his thinking was affected by watching members of his staff who are in committed same-sex relationships and thinking about "soldiers or airmen or marines or sailors who are out there fighting on my behalf and yet feel constrained."
Obama told ABC that his daughters were an influential factor and that his wife, first lady Michelle Obama, shared his views.
"You know, Malia and Sasha, they have friends whose parents are same-sex couples," Obama said. "There have been times where Michelle and I have been sitting around the dinner table and we're talking about their friends and their parents, and Malia and Sasha, it wouldn't dawn on them that somehow their friends' parents would be treated differently."
Obama added "it doesn't make sense to them and frankly, that's the kind of thing that prompts a change in perspective."
PRAISE FROM ACTIVISTS
Nearly two-thirds of Democrats support same-sex marriage, along with more than half of independents, while fewer than one-quarter of Republicans believe it should be allowed.
Obama's remarks were celebrated by Human Rights Campaign, a gay rights group, which said he had "made history."
Neera Tanden from the Center for American Progress described the president's expression of support as "another large step toward realizing this country's promise of equality."
Republican gay rights activists praised the decision but were more muted.
"I am sure the president's newly discovered support for marriage is cold comfort to the gay couples in North Carolina," said Christopher Barron, chief strategist of GOProud.
North Carolina voted on Tuesday to join 28 other states that have voter-approved constitutional bans on same-sex marriages, according to the National Conference of State Legislatures.
Six states and the District of Columbia allow gay and lesbian marriages. In Colorado on Wednesday, a bill that would have granted civil unions to same-sex couples failed to advance to a full vote.