"It is time to close this chapter in our history," Obama said in a statement after a test vote cleared the way for final action. "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 vote was 65-31. The House had passed an identical version of the bill, 250-175, on Wednesday.
Repeal would mean that, for the first time in American history, gays would be openly accepted by the military 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.
Rounding up a filibuster-proof majority in the Senate was a historic victory for Obama, who made repeal a campaign promise in 2008. It also was a political triumph for congressional Democrats who struggled in the final hours of the postelection session to overcome GOP objections on several legislative priorities before Republicans regain control of the House in January.
"As Barry Goldwater said, 'You don't have to be straight to shoot straight,"' said Senate Majority Leader Harry Reid, D-Nev., referring to the late GOP senator from Arizona.
Sen. John McCain, Obama's GOP rival in 2008, led the opposition. The Arizona Republican acknowledged he didn't have the votes to stop the bill and 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."
In the end, six GOP senators broke with their party on the procedural vote to let the bill move ahead and swung behind repeal after a recent Pentagon study concluded the ban could be lifted without hurting the ability of troops to fight.
Advocacy groups who lobbied hard for repeal hailed the vote as a significant step forward in gay rights. 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.
The Pentagon study 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, a majority were assigned to combat arms units. Nearly 60 percent of the Marine Corps and Army combat units, such as infantry and special operations, said in the survey they thought repealing the law would hurt their units' ability to fight.
The Pentagon's uniformed chiefs are divided on whether this resistance might pose serious problems.
Marine Corps Commandant Gen. James Amos has said he thinks lifting the ban during wartime could cost lives.
"I don't want to lose any Marines to the distraction," he told reporters this week. "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."
Adm. Mike Mullen and Marine Gen. James Cartwright, the chairman and vice chairman of the Joint Chiefs of Staff, respectively, have said the fear of disruption is overblown. 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. Among Marines in combat roles who said they have served alongside a gay person, 84 percent said there was no impact.