The partisan vote was a defeat for Senate Democrats and gay rights advocates, who saw the bill as their last chance before November's elections to overturn the law known as "don't ask, don't tell."
With the 56-43 vote, Democrats fell short of the 60 votes needed to advance the legislation. It also would have authorized $726 billion in defense spending including a pay raise for troops.
Senate Democrats attached the repeal provision to the defense bill in the hopes that Republicans would hesitate to vote against legislation that included popular defense programs. But GOP legislators opposed the bill anyway, thwarting a key part of the Democrats' legislative agenda.
Now, gay rights advocates say they worry they have lost a crucial opportunity to change the law. If Democrats lose seats in the upcoming elections this fall, repealing the ban could prove even more difficult -- if not impossible -- next year.
"The whole thing is a political train wreck," said Richard Socarides, a former White House adviser on gay rights during the Clinton administration.
Socarides said President Barack Obama "badly miscalculated" the Pentagon's support for repeal, while Democrats made only a "token effort" to advance the bill.
"If it was a priority for the Democratic leadership, they would get a clean vote on this," he said.
Democratic Sens. Blanche Lincoln and Mark Pryor of Arkansas sided with Republicans to block the bill. Senate Majority Leader Harry Reid, D-Nev., also voted against the measure as a procedural tactic. Under Senate rules, doing so enables him to revive the bill at a later date if he wants.
Republican Sen. Susan Collins of Maine had been seen as the crucial 60th vote because she supports overturning the military ban. But Collins agreed with her GOP colleagues that Republicans weren't given sufficient chance to offer amendments.
Reid allowed Republicans the opportunity to offer only one amendment to address GOP objections on the military's policy on gays.
Collins said she planned to vote against advancing the bill unless Democrats agreed to extend debate so that her colleagues could weigh in on other issues.
Jim Manley, a spokesman for Reid, said the senator would be willing to allow more debate on the bill after the November elections.
"Today's vote isn't about arcane Senate procedures," Manley said. "It's about a GOP's pattern of obstructing debate on policies important to the American people."
An estimated 13,000 people have been discharged under the law since its inception in 1993. Although most dismissals have resulted from gay service members outing themselves, gay rights' groups say it has been used by vindictive co-workers to drum out troops who never made their sexuality an issue.