Updated June 12, 2015, 2:40 p.m.

House Democrats may have cast the fatal votes that killed President Obama’s trade agenda on Friday morning, but the party responsible for its demise was a coalition whose numbers have diminished for decades and whose political clout has been questioned: the American labor movement.

The Obama administration believed it had the votes necessary to pass the most-contentious piece of its trade legislation—Trade Promotion Authority—that would allow the president to finalize agreements with Pacific Rim nations and the European Union. But the labor movement was not prepared to give up. Instead, it caught the administration off guard by launching a surprise attack on legislation known as Trade Adjustment Assistance, a program designed to help workers displaced by trade and one which Democrats—and organized labor—have overwhelmingly supported in the past. Just 40 House Democrats—less than one-quarter of the caucus—voted for the bill, which fell in a landslide, 302-126. By defeating the aid measure, the labor movement rendered the administration’s careful work rounding up votes for Trade Promotion Authority largely irrelevant.

As the margin of the defeat became clear, some Democrats scrambled to change their votes to 'No,' a measure of just how unpopular the measure had become. Republicans moved quickly to hold a vote on Trade Promotion Authority, but even though the bill received a majority of votes, it will not go to the president's desk because it does not match the Senate-passed package. GOP leaders could try to bring the assistance bill back for another vote next week, and the White House tried to downplay Friday’s loss as a momentary stumble. Press Secretary Josh Earnest referred to it as a “procedural snafu”—the same phrase he used to describe the trade package’s initial failure in the Senate earlier this spring. “It’s deja vu all over again,” Earnest said. Yet while the Senate had first fallen short by only a few votes, Obama would have to flip dozens of House Democrats to get it passed.

Trade Promotion Authority and Trade Adjustment Assistance—TPA and TAA in Beltway acronym-speak—have always been a package deal in Congress. Republicans support TPA because it leads to new trade agreements, while Democrats accept TAA as a consolation prize, because it mitigates the effect of outsourcing. (Although there are questions about how effective that assistance really is.) Yet once it became clear that Obama had secured enough Democratic votes to join most Republicans in passing TPA, the AFL-CIO took the astonishing step of announcing it would urge its progressive allies to oppose TAA as well. Because Republicans typically oppose the assistance piece of the trade package, the loss of Democratic support doomed the bill, and with it, the entire trade measure.

Democrats revolted even after their leader, Nancy Pelosi, negotiated a last-minute change to the proposals removing cuts to Medicare that would have paid for the assistance portion. And they rejected the most aggressive personal lobbying campaign that Obama has undertaken since the passage of his healthcare law five years ago. The White House has been wooing Democrats for weeks, even dangling the trappings of the presidency—Oval Office visits, rides on Air Force One, phone calls galore—in a way that’s been rare for Obama. (The D.C. pundit class has long urged him to engage in this sort of maneuvering to advance his legislative agenda; it doesn’t seem to have made much difference.) On Thursday evening, Obama made a surprise visit to the Congressional Baseball Game, where he smiled for pictures with lawmakers and reportedly button-holed Pelosi for 15 minutes on the trade bill. By Friday morning, he was back on Capitol Hill for a last-minute meeting with House Democrats just hours before the vote.

While Obama was glad-handing, administration officials were making a harder sell to progressives on the trade assistance bill. In language he usually reserves for denouncing the Tea Party, Earnest warned that Democrats who opposed TAA would not merely be voting against trade legislation but would be “signing the death certificate” for a crucial and longstanding aid program that expires at the end of the year. And in another sign of the party’s internal tumult, a senior House Democratic aide later told reporters that Representative Cedric Richmond, a Louisiana Democrat, had criticized strong-arm union tactics and AFL-CIO President Richard Trumka in a private party meeting, in an apparent effort to embarrass unions into backing down.

None of it worked.

At the AFL-CIO’s behest—and led by liberals including Rosa DeLauro, Keith Ellison, and Sandy Levin—Democrats defeated a bill they liked (TAA) to kill a bill they hated (TPA). Borrowing a page from the recent playbook of conservatives, Trumka and his allies threatened to launch primary challenges against Democrats who voted with the president. Obama responded by promising to campaign for Democrats who took the tough votes and stood by him. In the end, the fears of a union-backed challenge trumped the carrot of electoral help from a lame-duck president. “The difference between a liberal Democrat and a cannibal, according to LBJ, was cannibals don’t eat their own,” Henry Cuellar, a pro-trade Democrat from Texas, remarked a day before the vote, the Huffington Post reported.

The final indignity for Obama came in the minutes before the vote, when Pelosi—his erstwhile ally for six-and-and-half years—deserted him as well. The minority leader had remained publicly neutral for months while helping the White House behind the scenes. But in a floor speech announcing her position, Pelosi said she would do what Obama just hours before had explicitly asked his party not to do: Vote against TAA to tank TPA. Pelosi said she had always wanted to find “a path to yes,” and she voiced hope that by defeating Trade Promotion Authority now, Democrats could force Obama and Republicans to improve the package and try again. “That doesn’t mean I don’t think that the road can be repaired—just that it must be lengthened,” Pelosi said. “We need to slow this fast track down.” After the difficulty trade proponents had just to get the package through the Senate, however, it’s unclear if a do-over will be possible.

Labor’s opposition campaign even reached Republicans at the end, Speaker John Boehner acknowledged to reporters. After the union has locked down most of the Democrats,” the speaker lamented on Thursday, “they've turned their fire on conservative Republican households and shoving mail into these districts, raising other concerns from the right.”

For the labor movement, the pitched battle with Obama over trade marked the final destruction of an uneasy alliance. Despite their agreement on most of the president’s agenda, union leaders have been frustrated with the White House several times over the years. When Obama swept into office with Democratic majorities in 2009, the administration never pushed aggressively for the Employee Free Choice Act, a top labor priority. In the healthcare debate, unions prized the public option and swallowed hard when the administration—along with Democratic leaders in Congress—jettisoned it to push the bill to passage. Along with progressives, union leaders opposed Obama’s negotiations with Republicans for a grand bargain on the deficit, but then they joined Republicans in pushing for approval of the Keystone XL pipeline over the objections of environmentalists.

Yet none of those skirmishes compared to the all-out war unions fought in opposing Obama on trade. On this issue, the president could not blame his favorite foil for the defeat of his agenda. Led by Boehner and Paul Ryan, Republicans delivered their share of the votes for the trade bills, including more than twice their usual amount for Trade Adjustment Assistance. The president was brought down by Democrats, and by the political muscle of a movement that many had left for dead.