That meeting, described to POLITICO by multiple people familiar with the discussion, marked a turning point in the yearlong quest to reach a compromise by thrusting labor demands into the forefront and unifying Democrats behind the cause.

On Tuesday, top trade officials from the U.S., Mexico and Canada finalized a sweeping agreement to update the old NAFTA trade deal in an unusual alliance that won the backing of the powerful AFL-CIO labor federation, President Donald Trump and House Democrats. The pact appears to have widespread support in the House and Senate, giving Trump a major domestic policy victory and moderate Democrats something to sell back home as Washington is consumed by impeachment.

The deal didn’t come easy — and it was on the brink of death multiple times over the past year. Getting to yes required negotiations with an ideologically diverse coalition that included congressional Democrats, organized labor and Mexico's private sector, Canadian ministers and Trump’s hard-charging U.S. trade representative, Robert Lighthizer.

As recently as late October, AFL-CIO President Richard Trumka said he saw no reason to hurry. "What's the magic about this year?" Trumka told reporters.

Even as Trumka was saying that, though, a turning point had been reached. Pelosi's demand to the Mexican officials in September had pushed labor demands to the forefront and unified Democrats behind a possible deal.

Seade and Ebrard were caught off guard, unable to explain adequately how money in its government's labor department was allocated and how Mexico could live up to its promises on union protections. Lighthizer, who was not invited to the Pelosi meeting, was angry that his Mexican counterparts had blown the chance to demonstrate they were serious about meeting the U.S.’ labor demands.

Meanwhile, Pelosi, who was also working to win Trumka's approval — the linchpin to getting the deal through Congress — was unsure that Mexico would come through.

“It certainly had a catalyzing effect,” Dan Ujczo, a trade lawyer with Dickinson Wright, said of the Pelosi meeting. “You started to see even those kinds of moderate and left-leaning Democrats start speaking in unison with the more progressive and labor-oriented voices. So at that point, it became clear more concessions were needed.”

The story of how the compromise came together began a year earlier, when U.S., Mexican and Canadian trade officials signed the USMCA on the sidelines of a Group of 20 gathering in Buenos Aires, Argentina. Trump heralded the deal as a “groundbreaking achievement” that he predicted would sail through Congress.

Newly powerful House Democrats, who had just won the majority, were quick to push back. Senior members criticized the trade deal as “incomplete,” “flawed and dangerous” and “likely a dead-end in a Democratic House of Representatives.” It quickly became clear that further negotiations would be needed to garner support from House Democrats.

Talks started off slowly in early 2019, when the congressional year began with a 35-day shutdown. The historically large freshman class of Democrats faced a steep learning curve on what was in the trade agreement and whether they should back it. House leaders for months shrugged off a lack of forward movement by saying members were still educating themselves on the new deal.

By late spring, an increasingly frustrated Trump administration, which had few other legislative options on the horizon, was becoming impatient over lack of progress on the pact.

Lighthizer held dozens of meetings on the Hill to narrow down the list of concerns from Democrats on everything ranging from seasonal produce to duty-free thresholds. That’s when Democrats focused their demands for changes on four central issues: enforcement, labor and environmental standards and drug pricing provisions.

A deal in mid-May to lift steel and aluminum tariffs against Canada and Mexico marked a major step forward: If those duties had stayed, even staunch Republican supporters like Senate Finance Chairman Chuck Grassley were threatening to oppose the agreement.

But less than two weeks after that victory, Trump trampled on the goodwill it generated when he fired off a threat to impose sweeping tariffs against Mexico over unrelated issues related to migrants at the border.

The ensuing furor prompted a week of frantic negotiations between the two countries as Mexico desperately tried to avoid the sweeping penalties. Democrats and their aides have often reminded reporters that they started negotiations with Lighthizer a few weeks later than originally anticipated because of that threat from the Oval Office.

It was only after the immigration issues were resolved that Pelosi and Lighthizer worked out an arrangement to have him negotiate directly with a group of nine House Democrats, specifically chosen for the varied interests they represented from across the caucus.

“Pelosi is a master legislative tactician,” Rep. Henry Cuellar (D-Texas), a staunch USMCA supporter who has been closely tracking the deal, said in a recent interview. “She knew exactly who to put on that working group to ensure everyone had a seat at the table.”

The group — whose members ranged from moderate New Democrat Rep. Terri Sewell of Alabama to progressives like Connecticut Rep. Rosa DeLauro — began meeting regularly with Lighthizer in mid-June as administration officials ramped up a push to see a vote on the deal before summer recess began six weeks later.

Some issues were worked out quickly: An agreement to strip out protections for biologic drugs, which opponents say would allow drug companies to keep prices high, was struck in those first few weeks, said Rep. Earl Blumenauer(D-Ore.), who focused on the issue for the working group. It was deliberately kept under a proverbial lock-and-key to help prevent a propaganda campaign from the powerful pharmaceutical lobby, which could have derailed the handshake deal.

The early win for Democrats boosted members’ confidence and showed the administration was willing to make concessions. But compromises on other areas — specifically, labor and enforcement provisions — remained elusive. The caucus began to splinter over summer recess as moderate Democrats grew increasingly anxious to hold a vote on the agreement.

That divide only worsened as the House formalized its impeachment inquiry and battleground Democrats feared getting hammered at home over those investigations amid relatively few legislative accomplishments.

Labor conversations dominated the fall. Pelosi would not move the pact forward without a nod from Trumka, whose approval in turn would give even labor-friendly Democrats cover to vote for the pact.

But the influential labor leader — who one person involved in talks called the “key validator” of the negotiations — told members of the working group he was so far unwilling to budge. Amid stalled negotiations, House Ways and Means Chairman Richard Neal (D-Mass.), who led the working group, at one point called for Trumka to sit down directly with Lighthizer and his trade staff while members returned to their districts for an early November recess.

“I think everyone would acknowledge that Trumka is key,” Rep. John Larson (D-Conn.), a working group member, said at the time.

With a freshman class growing more anxious by the day, Pelosi summoned Trumka to the Hill in mid-November to placate members who were pushing for a vote. In a private caucus meeting, he told members the pact was on the “five-yard line” and that the AFL-CIO was almost ready to support it. But the group hadn’t supported any deal in nearly two decades, and there was skepticism the pieces would ever fall together.

“It feels like we’ve been at the five-yard line for awhile,” Rep. Jimmy Gomez (D-Calif.), another working group member, said afterward.

Ultimately, the pieces clicked. Mexican negotiators spent most of the past two weeks in Washington engaged in grueling negotiations at USTR. Major industry groups in the private sector lashed out at the U.S.’ demands, accusing some participants — potentially Trumka — of pushing so hard that it appeared they didn’t want a deal at all.

At a make-or-break moment, Seade, Mexico’s chief negotiator, did not show up for a planned meeting with Lighthizer last week, instead spending time appealing to some private-sector groups in Mexico. But by Saturday, the two sides had worked out the major sticking points.

Pelosi called over to USTR as Lighthizer held a final meeting with Seade. She then spent the weekend in talks with Neal and Trumka to get their support. Trumka was on a hunting expedition, but still spoke with the two lawmakers frequently.

Trumka, who has long had a tense relationship with Trump, called over to the White House on Monday to speak with the president on the agreement. As one final sweetener for organized labor, he asked Trump to move a pensions rescue bill forward alongside the USMCA.

Trump replied that he would consider it, according to a person familiar with the call. Trumka then briefed his executive council and gave Pelosi his blessing on the compromise.

“You know what I’ve said: These have been the fights,” Pelosi told fellow Democrats at a closed-door caucus meeting Tuesday morning. “And we stayed on this, and we ate their lunch.”

Sabrina Rodriguez, Ian Kullgren and Heather Caygle contributed to this report.