"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," Obama said.
A beaming Obama signed the bill at the Interior Department, a location chosen to accommodate a larger than normal audience that cheered, chanted and applauded throughout the ceremony.
"This is a good day," Obama told the crowd. "This is a very good day."
The new law ends the 17-year-old "don't ask, don't tell" policy that forced gays to hide their sexual orientation or face dismissal. More than 13,500 people were discharged under the policy. Its repeal comes as the American public has become more tolerant on such issues as gay marriage and gay rights in general.
"I say to all Americans, gay or straight, who want nothing more than to defend this country in uniform, your country needs you, your country wants you, and we will be honored to welcome you into the ranks of the finest military the world has ever known," Obama said.
Pentagon officials must first complete implementation plans before lifting the old policy - and the president, defense secretary and chairman of the joint chiefs must certify to lawmakers that it won't damage combat readiness, as critics charge.
Pentagon officials must first complete implementation plans before lifting the old policy - and the president, defense secretary and chairman of the joint chiefs must certify to lawmakers that it won't damage combat readiness, as critics charge. Opponents of the repeal also had said it would harm unit cohesion; could prompt some to leave the services or not to sign up in the first place; and be a distraction at a time when the armed forces are fighting two wars - all issues the Pentagon is treading carefully as it tries to come up with an implementation plan.
But Obama said: "We are not going to be dragging our feet to get this done."
The signing ceremony was a breakthrough moment for the nation's gay community, the military and for Obama himself. The president vowed during his 2008 campaign to repeal the law and faced pressure from liberals who complained he was not acting swiftly enough.
For Obama, it was the second high-profile bill signing ceremony within a week. On Friday, he signed into a law a tax package he negotiated with Republicans that extended Bush-era tax rates for two more years, cut payroll taxes and ensured jobless benefits to the unemployed for another year.
The two events, however, could not have been more different in tone.
The tax deal divided Democrats and forced Obama to accept extensions of tax cuts for the wealthiest, a step he had promised to not take. With Senate Republican leader Mitch McConnell at his side during that bill signing, Obama seemed dutiful and subdued.
By contrast, the emotion of Wednesday's ceremony defined it; even the president himself said he was "overwhelmed" by the moment. The gay activists and supporters packed in the room hooted, applauded and shouted in joy at the president, shedding any sense of a contained, formal event.
As Obama signed the bill into law, someone in the back of the room yelled: "We're here, Mr. President. Enlist us now!"
"I couldn't be prouder," Obama said.
Obama hailed the "courage and vision" of Defense Secretary Robert Gates and praised Gates and Joint Chiefs of Staff Chairman Adm. Mike Mullen, who advocated changing the law.
Among those in attendance at the ceremony was the son of a World War II veteran who was saved by a gay comrade during the Battle of the Bulge. Also present was Marine Staff Sgt. Eric Alva, the first American wounded in the war in Iraq who has spoken out against the Pentagon policy.
The Pentagon now must address the practical consequences of the law. Guidelines must be completed that cover a host of questions, from how to educate troops to how sexual orientation should be handled in making barracks assignments.
White House spokesman Robert Gibbs said Obama thinks actual implementation of the new law will be "a matter of months."
Military officials and gay rights groups have been warning gay troops not to come out yet, as the law will not go into effect until certification - and after that, a 60-day waiting period.
The new law is the second of three expected victories in what's turned out to be a surprisingly productive lame-duck Congress for Obama . Weeks after his self-described "shellacking" in the midterm vote, he's won lopsided approval of a tax cut compromise, and the Senate is poised to deliver his top foreign policy goal: ratification of a new nuclear arms treaty with Russia.
Born 17 years ago as a compromise between President Bill Clinton and a resistant Pentagon, the "don't ask, don't tell" policy became for gay rights campaigners a notorious roadblock on the way to full acceptance.
Yet he has also faced rising discontent among gay activists who believed he hadn't moved forcefully enough. He's been heckled at campaign appearances over AIDS funding and the failure to end the military service ban.
Obama countered that as commander in chief, he had to ensure the ban's end is carefully prepared for.
That's just what the bill from Congress mandates.
"The implementation and certification process will not happen immediately; it will take time," Air Force Chief of Staff Gen. Norton Schwartz warned in an e-mail that went out right after Saturday's Senate vote. "Meanwhile, the current law remains in effect. All Air Force members should conduct themselves accordingly."
Military and administration officials are wrestling with numerous legal questions raised by the end of the ban - knowing that courts are waiting in the wings. They include what to do about pending expulsion proceedings, and when those ousted under the old policy might apply to rejoin the armed forces.
Associated Press writers Mark S. Smith and Ben Feller contributed to this report.