Updated

President Obama feigned opposition to gay marriage for most of his political career, compromising his true beliefs out of concern it could hurt him with voters, Obama's longtime political adviser disclosed in a new book.

David Axelrod, who served as a top White House adviser after helping Obama get elected, said Obama begrudgingly followed his advice that he would face strong opposition from African American religious leaders and others if he let it be known he supported gay marriage. He said Obama "modified his position" to say he supported civil unions -- but not same-sex marriage.

"Having prided himself on forthrightness, though, Obama never felt comfortable with his compromise and, no doubt, compromised position," Axelrod wrote in the memoir "Believer: My Forty Years in Politics," released Tuesday.

Axelrod's disclosure affirmed what was widely suspected for years: that Obama's May 2012 announcement that he supported gay marriage came long after the president had personally come to that conclusion. The year earlier, Obama and the White House had started saying his position was "evolving," leading many to believe he was holding off on a public embrace of gay marriage for fear it could damage his re-election prospects.

"If Obama's views were `evolving' publicly, they were fully evolved behind closed doors," Axelrod wrote.

When he finally said he felt gay marriage should be legal, it was only after Vice President Joe Biden declared his support for gay marriage during an interview, upping the pressure on Obama to make his current views clear ahead of the election. Axelrod said Obama's advisers told him it could cost him a few key states including North Carolina, but that Obama was "champing at the bit to announce his support."

The public airing of Obama's overtly political considerations comes as the Supreme Court prepares to resolve the gay marriage issue nationwide in a few months.

White House spokesman Josh Earnest said he wouldn't dispute Axelrod's account, noting that it was informed by Axelrod's "front-row seat to history." But he said Obama's record of fighting for expanded rights for gays and lesbians "speaks to this even better than I possibly could."

Fred Sainz, vice president of the gay rights group the Human Rights Campaign, said gay rights activists suspected all along that Obama supported gay marriage because he had indicated his support in a 1996 questionnaire before backtracking years later.

"While perhaps political, the `evolution' narrative he used was helpful," Sainz said. "That journey was one that resonated with many Americans as they went on their own journeys toward greater acceptance."