On Monday, President Donald Trump formally withdrew the United States from one of his predecessor’s signature foreign policy projects, ending an eight-year endeavor Barack Obama had hoped would reshape American influence on four continents.

It was, oddly, a victory for the Democratic Party.

Labor unions, environmental groups, public health experts, liberal economists and consumer watchdogs had all been denouncing the Trans-Pacific Partnership for years. The overwhelming majority of Democrats in both the House and Senate repeatedly voted to block it. Former Secretary of State Hillary Clinton and Sen. Bernie Sanders (I-Vt.) both officially opposed the trade pact with 11 other nations during the 2016 election. Anti-TPP protesters shouted down speakers during the Democratic National Convention last summer, a spectacle overshadowed only by Michelle Obama’s soaring speech that same night.

President Obama lost the Trans-Pacific Partnership because his closest allies spurned him, buying time for an unforeseen political enemy to eventually deliver the killing blow. Liberal Democrats in Congress and progressive activists won a long-shot battle against a popular president amid a sea change in economic thought.

* * *

When Obama called for the TPP at the outset of his administration, he presented it as a tough new policy targeting China. The U.S. would win allies by creating a new trading bloc to counter the emerging superpower’s growing influence in the region. This, the thinking went, would protect American interests and spread American ideas about human rights and democracy.

These lofty political ideals were complicated almost immediately. When the administration began to corral global leaders, it made no apologies for courting notoriously repressive regimes as potential partners in the anti-China bulwark. The administration postponed big questions about political reform, focusing instead on securing robust new investor rights as a bedrock principle of any final trade deal. American negotiators demanded that all parties to the TPP grant multinational corporations the right to challenge domestic laws and regulations before an international tribunal if they believed that government rules had hampered their investments. The Obama team also pressed hard to enhance the power of pharmaceutical companies and other intellectual property owners to raise prices by wielding state-sponsored monopolies.

The ultimate economic impact of a long-term treaty among 12 nations covering every aspect of commercial life was difficult to forecast, but the fundamental message was clear. Anyone who wanted to join this new alliance with the United States had to be willing to expand the political power of the wealthy.

The Obama administration didn’t invent this idea. The text of the TPP was based on the 1993 North American Free Trade Agreement, a joint effort from Presidents George H.W. Bush and Bill Clinton, who believed the world was suffering from a “capital shortage” holding back global development. Owners of stocks, bonds and intellectual property rights were being unduly restrained by tariffs and excessive government rules, the argument went. Liberating them would unleash a new era of investment and, inevitably, progress.

This idea undergirded the 1990s free trade explosion. One of Clinton’s chief arguments in favor of ushering China into the World Trade Organization in 2000 was the promise of expanded trade leading to democratic reform. It became the bipartisan consensus inside the Beltway, one that just happened to offer immediate rewards for the donor classes in both parties.

The 2008 financial crisis caused many economists to rethink this consensus, but it took years for political leaders to make the connection between financial calamity and trade policy. The Obama administration was committing itself to a Clintonian approach on a major trade pact at just the moment when these ideas were beginning to lose their intellectual moorings.

Environmentalists, lead by the Sierra Club, screamed that the TPP would undercut efforts to combat climate change by expanding trade in fossil fuels, and denounced the political powers granted to corporations under the supranational Investor State Dispute Settlement process. Labor unions were appalled by the prospect of American workers competing for jobs with Vietnamese workers receiving a 64-cent minimum wage. Doctors Without Borders warned that the deal in the works would jeopardize access to lifesaving medicine for people in the developing world. In 2010, the consumer group Public Citizen ― a longtime critic of American trade policy ― began coordinating with a handful of other early opponents, including the Sierra Club, the Communication Workers of America, the Teamsters and Citizens Trade Campaign, on a strategy to defeat the entire pact.

Other countries seemed to be listening to the complaints. In December 2011, the Obama administration put its prescription drug proposal on the table, calling for long-term monopolies on a host of drugs, particularly “biologics” ― a new generation of cancer treatments, according to an activist familiar with the negotiations. The proposal didn’t move for 18 months.

“Nobody would even talk to the U.S. about that,” the activist said. “And you just can’t reach an agreement this big with that being an unresolved issue for years.”

The delays were playing into the hands of TPP opponents. Taking a page from congressional lobbyists, anti-TPP groups who recognized they could not derail the talks worked instead to prolong them, hoping for an eventual deus ex machina. If congressional trade votes could be postponed until the spring of 2014, neither Republican nor Democratic leaders would want to bring up a controversial issue ahead of the midterm elections. After the midterms, activists hoped to delay the matter until the 2016 election was in gear. Trade is always unpredictable in presidential campaigns; Obama and Clinton had both railed against NAFTA in 2008, only to reverse course later. If the deal was still in the air by October 2015, TPP opponents could buy an entire extra year.

* * *

By early 2014, the White House recognized it had a serious problem with its progressive critics on and off Capitol Hill. But instead of trying to win allies by making concessions, the Obama team embarked on public and private campaigns to convince critics they just didn’t understand how great TPP really was.

Publicly, the administration insisted the deal would include tough environmental and labor protections, and it downplayed union concerns about offshoring by touting the potential for increased exports. The TPP wasn’t an extension of an economic agenda dating back to 1993, Obama declared ― it was a complete overhaul of the international economic order. Since Mexico and Canada were part of the negotiations, the administration said it was making good on Obama’s 2008 pledge to “renegotiate” NAFTA. TPP opponents, Obama said, were advocates for “the status quo.”

“Get informed,” Obama told congressional Democrats in a private meeting two years ago. “Not by reading The Huffington Post.”

It didn’t work. U.S. Trade Representative Michael Froman angered progressive Democratic lawmakers in private meetings. Rep. Sander Levin (D-Mich.), the top Democrat on the key trade committee in the House, was so insulted by the administration’s refusal to work with him that he publicly vowed to kill the pact.

Obama, in turn, was getting fed up with the resistance from his left flank. When Sen. Elizabeth Warren (D-Mass.) began voicing opposition to the deal’s package of investor rights, Obama lashed out, telling the press her criticisms were “dishonest” and “bunk.” Hundreds of law professors sided with Warren.

This wasn’t just an embarrassing intraparty feud. It was a counterproductive legislative strategy, one that wasn’t winning Obama any new supporters on Capitol Hill. And the administration’s claims about progressive perks in the deal were taking body blows. Sen. Bob Menendez (D-N.J.) slipped an amendment into a trade bill barring the United States from signing trade deals with any country it officially designated as among the world’s worst human trafficking offenders. It was an indirect maneuver targeting Malaysia, a TPP country with a long history of forced labor violations where mass graves of hundreds of trafficking victims had just been uncovered. The administration responded by upgrading Malaysia on its annual Tracking In Persons report, undermining its claims that TPP would check labor abuses and outraging Human Rights Watch and other nonpartisan advocates.

But the real problem for Obama was in the House, where Rep. Rosa DeLauro (D-Conn.) had been organizing Democrats against the pact. In early 2016, she partnered with a new ally, Rep. Walter Jones, a conservative Republican from North Carolina. DeLauro and Jones organized breakfasts and staff meetings, and updated each other on the opposition within their respective parties.

“The only thing we agree upon is probably the trade issues, philosophically,” Jones told HuffPost. “But we just kind of came together... From the Republican point of view, [TPP is] just another example of these agreements threatening the sovereignty of a nation. We continue to give more than we receive.”

Jones is an unusual Republican who grew accustomed to breaking with his party during the George W. Bush years, voting frequently against war, Wall Street and free trade. The GOP had been ardently supportive of the Clinton free trade project, seeing it as a win for its corporate donor class. But Trump’s primary campaign had scrambled the way elected GOP leaders saw their voter base, which seemed to be siding with Jones over the Koch brothers. Trump’s attack on the party line on trade wasn’t hurting him — it was bolstering his popularity. It eventually played a key role in winning him the general election, as former Rust Belt states flipped from red to blue.

Activists had hoped the presidential race would buy them time to block the trade deal. Instead, the race completely upended the Beltway consensus. Clinton, Trump and Sanders all repeatedly criticized the deal. A nervous White House began pressing congressional leaders for a vote on TPP in the early months of 2016, recognizing the possibility that the long campaign would allow a public consensus against the pact to solidify. Republicans were afraid to confront their base on a core proposal from their presidential candidate, while Clinton was trying to bring disgruntled Sanders supporters into the fold. DeLauro and Jones had more votes than Paul Ryan and Nancy Pelosi.

* * *

The intellectual ground had also shifted during the eight-year talks. China’s role in the WTO clearly had not generated the momentum for democratic reform Bill Clinton had hoped for. Wages in Mexico had not budged since NAFTA’s implementation. Escalating political turmoil in Greece and the Brexit vote forced hard re-evaluations of the political viability of a large-scale free trade regime. And collapsing communities in the United States were lining up behind a demagogue.

In April 2016, former World Bank economist Branko Milanovic published an influential book warning that the massive gains for the super-rich from the last 30 years of globalization were fueling both an angry populism and plutocracy in developed countries. At a conference in August, Anne-Marie Slaughter, a close Hillary Clinton confidante who runs the ardently centrist New America Foundation think tank, openly questioned TPP’s ideological foundation.

“There’s a sense that the system is not working, that the free trade mantra that I grew up with, which is, it’s good for everybody, it expands the pie, we should absolutely want it... Well, that system ― a lot of people don’t think is working,” Slaughter said.

Financial Times columnist Martin Wolf, once an ardent free trade advocate, went even further. “Those of us who wish to preserve both liberal democracy and global capitalism must confront serious questions,” Wolf wrote. “One is whether it makes sense to promote further international agreements that tightly constrain national regulatory discretion in the interests of existing corporations.”

All of this undermined Obama’s ability to make the case for TPP on its merits. The pitch instead became one of the need for the United States to save face. The U.S. had led these talks for years. Walking away would be an embarrassment on the global stage.

And so it proved to be. But perhaps not so embarrassing for Obama as watching an eight-year project fall to an alliance between his own party and his successor, Donald Trump.

Sign up for the HuffPost Must Reads newsletter. Each Sunday, we will bring you the best original reporting, long form writing and breaking news from The Huffington Post and around the web, plus behind-the-scenes looks at how it’s all made. Click here to sign up!