President Obama may have been forced to come out sooner than he wanted on gay marriage, but he deserves tremendous credit for taking a risky political stand on one of the more divisive social issues of the day.

Obama had long said his position on same-sex relationships was evolving beyond his support for civil unions. But after Vice President Biden and Education Secretary Arne Duncan broke ranks this week and said they support gay marriage, the pressure was on Obama to make up his mind.

"I've always been adamant that gay and lesbian Americans should be treated fairly and equally," Obama said Tuesday.  "At a certain point 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."

There had been signs that Obama would eventually reverse his opposition to gay marriage, the most recent being the decision by the Justice Department not to defend the constitutionality of the Defense of Marriage Act.

Obama said his mind was changed after reflecting on the relationships of gay friends and conversations with his wife and two daughters. It had been widely speculated that he might make such an announcement after the presidential election, but after Biden and Duncan's statements, Obama supporters such as former Gov. Ed Rendell challenged Obama to "man up" and tell the truth about his position.

Political opponents say Obama's changed view, coming six months before the November election, was calculated. But he has just as much to lose as he does to gain with the historic declaration. Polls show Americans evenly split on the issue, and many gay-rights proponents were already inclined to vote for Obama.

That's because expected Republican presidential nominee Mitt Romney not only supports a constitutional amendment banning gay marriage, but he also opposes civil unions. Obama's decision may  galvanize gays and young people, but his new position will likely hurt him among some conservative Democrats and independents.

Obama also can't ignore that more than 30 states, most recently North Carolina, a key battleground state in presidential elections, have passed laws prohibiting same-sex marriages. If his announcement was a political calculation, it couldn't have been an easy one, and it may yet prove to be an error.

Many gay-rights activists are disappointed that the announcement came unadorned. Obama aides say the president has no plans to push for any changes in federal law, and that he believes the issue should be settled by the states. Obama should know by his study of American history that it typically takes uniform, federal action to end discrimination.

In particular, the question of how to allow same-sex marriage while preserving the integrity of constitutional provisions meant to protect religious institutions, which should not be forced to disavow their own tenets, cannot be left to the individual states to decide. Then there is the question of reciprocity: Will a gay marriage in one state be recognized in another?

Like Obama, many Americans have wrestled with the issue of gay marriage. But with the president coming out of the closet with his views, maybe it will be easier for others to follow his lead.