WASHINGTON - President Obama on Wednesday signed the repeal of the ban on gays serving openly in the nation's armed forces, fulfilling a campaign pledge and ushering in an uncertain new era not just for the military but for the hot-button issue of gender and sexual politics.

More than 500 advocates, lawmakers, members of the military, and former soldiers who had been discharged for homosexuality crowded into the ceremony, held in an Interior Department auditorium to accommodate the crowd.

The atmosphere was jovial and a little rowdy, with chants of "Yes, we did!" and "U-S-A, U-S-A!" Many shouted out, "Enlist us now!"

"I am just overwhelmed," Obama said. "This is a very good day."

How soon the repeal will take effect, allowing gays and lesbians to join the military and serve openly for the first time, remained uncertain. The president made clear the repeal will not take effect until he and top defense officials certify the military's readiness, as the law requires, but he said, "We are not going to be dragging our feet to get this done."

In an interview Tuesday that was published on the website of the gay newspaper The Advocate, Obama said he thought implementation would be a matter of months, though some Pentagon officials have suggested it could take as long as a year.

"We will get this done in a timely fashion, and the chiefs are confident that it will get done in a timely fashion," Obama said, referring to the heads of the four military branches. "They understand this is not something that they're going to be slow-walking."

He said Adm. Mike Mullen, chairman of the Joint Chiefs of Staff, had promised to take with him during his vacation the recommendations on how to lift "don't ask, don't tell" that were part of an eight-month Pentagon study of attitudes toward gays in the military.

Obama also cited assurances from Marine Commandant Gen. James Amos, the most vocal of the service heads to oppose ending "don't ask, don't tell," that the Marines would implement the new policy without hesitance.

Obama was less certain in the interview on whether the repeal would lead to other changes in the way gays and lesbians are treated, particularly on the issue of marriage.

Obama has said previously that he favors civil unions but opposes same-sex marriage, but in The Advocate interview he said that his views on the issue "are evolving." Later Wednesday, he said in response to a news-conference question about gay marriage that "I struggle with this."

In The Advocate interview, he also said his administration is considering a "range of options" to counter the Defense of Marriage Act, which defines marriage as between a man and a woman and allows states to refuse to recognize same-sex marriages performed in other states.

Obama made no mention of the gay-marriage issue as he signed the "don't ask, don't tell" repeal into law.

He predicted that people would look back at this "historic milestone" and "wonder why it was ever a source of controversy in the first place."

Obama said the repeal "will strengthen our national security and uphold the ideals that our fighting men and women risk their lives to defend."

"No longer will tens of thousands of Americans in uniform be asked to live a lie, or look over their shoulder, in order to serve the country that they love," he said.

Among the lawmakers Obama singled out at the ceremony for their efforts in getting the repeal passed was Rep. Patrick J. Murphy (D., Pa.).

After he signed the law, Obama shook hands with many in the audience.

Walker Burttschell, 28, of Miami, was one of the first to thank him personally. "It was so good to shake his hand," he said. Burttschell said he left school right after the Sept. 11, 2001, attacks to join the Marines but was outed two years later, then discharged after someone broke into his e-mail account.

With the repeal, Burttschell said, he is considering re-enlisting.