The US Senate voted yesterday to repeal the ban on gay people serving openly in the military, paving the way for President Obama to sign a law ending the policy this week.

However, the defence secretary, Robert Gates, who had pushed for the change, warned gay men and women in the military that the current "don't ask, don't tell" policy will remain in effect for some time while the new rules are put in place.

Obama said in a statement: "By ending 'don't ask, don't tell' 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. And no longer will many thousands more be asked to live a lie in order to serve the country they love."

The Senate voted by 65-31 to end the 17-year-old ban following its passage through the Democratic-led House of Representatives. Democratic leaders had pushed for its passage before the end of the current session because Republicans, many of whom did not support the change, will control the House of Representatives in January and have greater numbers in the Senate.

Gay men and women were barred from serving in the military until 1993, when "don't ask, don't tell" allowed them to serve as long as they kept their sexual orientation secret.

The policy has seen more than 13,000 men and women expelled from the American military but a Pentagon report found that most in the armed services did not object to lifting the ban.

Speaking at a news conference with Senate leaders following the vote, former air force major Mike Almy said he was dismissed after another officer read his private e-mails to loved ones.

"There is nothing more that I want than to resume my career as an officer and a leader in the Air Force," he said.Gates said that once Obama signed the bill, the government would begin the "planning necessary to carry out this change".

The legislation gives the Pentagon an undetermined amount of time – possibly months – to educate service members and prepare for the policy change before it "certifies" repeal.

"It is therefore important that our men and women in uniform understand that while today's historic vote means that this policy will change, the implementation and certification process will take an additional period of time," Gates said.

Opponents of gay men and women serving openly in the military argued that lifting the ban would undermine order and discipline and harm unit cohesiveness, especially among combat troops.

Republican opposition was largely led by Obama's 2008 White House challenger, John McCain, a former navy pilot and prisoner of war in Vietnam.

McCain said it may be too early to end the ban and challenged the Pentagon's forecast of little impact if the policy were lifted. In a Senate speech, he argued against imposing a change while the country is at war.

"This debate is not about the broader social issues that are being discussed in our society, but what is in the best interest of our military at a time of war," McCain said.