Obama was expected to sign it next week, although the change wouldn't take immediate effect. The legislation says the president and his top military advisers must certify that lifting the ban won't hurt troops' fighting ability. After that, there's a 60-day waiting period for the military.
The Senate vote was 65-31. The House had passed an identical version of the bill, 250-174, 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.
Defense Secretary Robert Gates and other senior military leaders have supported repealing the policy. A recent Pentagon study showed that most service members do not object to serving with homosexuals.
With an end to the ban, "no longer will our nation be denied the service of thousands of patriotic Americans forced to leave the military, despite years of exemplary performance, because they happen to be gay," Obama said in a statement. "And no longer will many thousands more be asked to live a lie in order to serve the country they love."
The Associated Press contributed to this report.