Obama was expected to sign the bill into law next week, although changes to military policy probably wouldn't take effect for at least several months. Under the bill, the president and his top military advisers must first certify that lifting the ban won't hurt troops' ability to fight. After that, the military would undergo a 60-day wait period.
Repeal would mean that, for the first time in American history, gays would be openly accepted by the armed forces and could acknowledge their sexual orientation without fear of being kicked out.
More than 13,500 service members have been dismissed under the 1993 law.
"It is time to close this chapter in our history," Obama said in a statement. "It is time to recognize that sacrifice, valor and integrity are no more defined by sexual orientation than they are by race or gender, religion or creed."
The Senate voted 65-31 to pass the bill, with eight Republicans siding with 55 Democrats and two independents in favor of repeal. The House had passed an identical version of the bill, 250-175, earlier this week.
Supporters hailed the Senate vote as a major step forward for gay rights. Many activists hope that integrating openly gay troops within the military will lead to greater acceptance in the civilian world, as it did for blacks after President Harry Truman's 1948 executive order on equal treatment regardless of race in the military.
"The military remains the great equalizer," said Sen. John Kerry, D-Mass. "Just like we did after President Truman desegregated the military, we'll someday look back and wonder what took Washington so long to fix it."
Sen. John McCain, Obama's GOP rival in 2008, led the opposition. Speaking on the Senate floor minutes before a crucial test vote, the Arizona Republican acknowledged he couldn't stop the bill. He blamed elite liberals with no military experience for pushing their social agenda on troops during wartime.
"They will do what is asked of them," McCain said of service members. "But don't think there won't be a great cost."
How the military will implement a change in policy, and how long that will take remains unclear. Senior Pentagon officials have said the new policy could be rolled out incrementally, service by service or unit by unit.
In a statement issued immediately after the vote, Defense Secretary Robert Gates said he will begin the certification process immediately. But any change in policy won't come until after careful consultation with military service chiefs and combatant commanders, he said.
"Successful implementation will depend upon strong leadership, a clear message and proactive education throughout the force," he said.
Adm. Mike Mullen, chairman of the Joint Chiefs of Staff, said he welcomes the change.
"No longer will able men and women who want to serve and sacrifice for their country have to sacrifice their integrity to do so," he said. "We will be a better military as a result."
Sen. Carl Levin, a chief proponent of repeal, said he has received a commitment from the administration that it won't drag its heels.
"We hope it will be sooner, rather than later," he said.
The fate of "don't ask, don't tell" had been far from certain earlier this year when Obama called for its repeal in his State of the Union address. Despite strong backing from liberals in Congress, Republicans and conservative Democrats remained skeptical that lifting the ban could be done quickly without hurting combat operations in Iraq and Afghanistan.
In February, Mullen provided the momentum Obama needed by telling a packed Senate hearing room that he felt the law was unjust. As chairman of the Joint Chiefs of Staff, Mullen became the first senior active-duty officer in the military to suggest that gays could serve openly without affecting military effectiveness.
"No matter how I look at the issue," Mullen said, "I cannot escape being troubled by the fact that we have in place a policy which forces young men and women to lie about who they are in order to defend their fellow citizens."
With Mullen's backing, Gates ordered a yearlong study on the impact, including a survey of troops and their families.
The study, released Nov. 30, found that two-thirds of service members didn't think changing the law would have much of an effect. But of those who did predict negative consequences, most were assigned to combat arms units. The statistic became ammunition for opponents of repeal, including the service chiefs of the Army and Marine Corps.
"I don't want to lose any Marines to the distraction," Gen. James Amos, head of the Marine Corps, told reporters. "I don't want to have any Marines that I'm visiting at Bethesda (Naval Medical Center) with no legs be the result of any type of distraction."
Mullen and Gates counter that the fear of disruption is overblown and could be addressed through training. They note the Pentagon's finding that 92 percent of troops who believe they have served with a gay person saw no effect on their units' morale or effectiveness.
But even with backing from Gates and Mullen, the bill appeared all but dead this month when Senate Republicans united against it on procedural grounds. In last-minute wrangling, Senate Majority Leader Harry Reid was able to revive the bill during the rare Saturday session with just days to go before the lame-duck session was to end.
The Republicans who voted for repeal said the Pentagon study on gays and assurances from senior military leaders played a crucial role.
"The repeal of 'don't ask, don't tell' will be implemented in a common sense way," said Ohio Republican Sen. George Voinovich. "Our military leaders have assured Congress that our troops will engage in training and address relevant issues before instituting this policy change."
Advocacy groups were jubilant following the Senate's initial test vote that passed 63-33 and set up final passage. The Servicemembers Legal Defense Network called the issue the "defining civil rights initiative of this decade." Supporters of repeal filled the visitor seats overlooking the Senate floor, ready to protest had the bill failed.
"This has been a long-fought battle, but this failed and discriminatory law will now be history," said Joe Solmonese, president of the Human Rights Campaign.
At least 25 countries allow gays to serve openly in the armed forces, among them Britain, Canada and Israel, according to the Palm Center, a research institute at the University of California, Santa Barbara.
Pentagon study: http://tinyurl.com/23lxc49
Servicemembers Legal Defense Network: http://www.sldn.org/
Information on the bill, H.R. 2965, can be found at http://thomas.loc.gov