Open this photo in gallery Conor Lamb celebrates with his supporters at his election night party in Canonsburg, Pa., on March 14, 2018. Gene J. Puskar/The Associated Press

The Democrats have pulled off an upset in in what was supposed to be a safe Republican congressional seat, dealing a blow to U.S. President Donald Trump ahead of midterm elections that could determine the fate of his administration.

Unfolding in western Pennsylvania Tuesday – just days after Mr. Trump unveiled tariffs meant to shore up the steel industry, which is historically important to the region’s economy – Democrat Conor Lamb narrowly bested Republican Rick Saccone in a district that backed Mr. Trump by 19 points in 2016.

Analysis: Pennsylvania election: Sound and fury, signifying...almost nothing

Story continues below advertisement

“Tonight, we celebrate regaining our voice and our vote in the great business of governing this country we love,” he told a hotel ballroom full of cheering supporters around 12:45 a.m.

The fight over Pennsylvania’s 18th congressional district, which stretches from the Pittsburgh suburbs through a coal-producing region to the West Virginia border, was a test of Mr. Trump’s ability to hold on to the key blue-collar Rust Belt demographic that secured his ascent to the White House.

The election is also a trial run for the Democrats’ efforts to win back conservative, working-class voters who bolted from the party two years ago. Winning control of Congress in November would give them the power to obstruct Mr. Trump’s agenda and try to impeach him.

The vote comes just days after Mr. Trump announced tariffs of 25 per cent on steel and 10 per cent on aluminum, setting the stage for a global trade war – and increasing the pressure on Canada to reach a deal with Washington on the North American free-trade agreement, a precondition for Mr. Trump granting Ottawa a permanent exemption from the levies.

It squarely puts economic nationalism at the crux of both Mr. Trump’s domestic survival and the United States’ relationship with the rest of the world.

“With the tariffs, maybe we can get on a level playing field with the exports and imports,” said Bill Nagel, a greying, bearded 48-year-old, as he stood at the back of a weekend rally for Mr. Trump and Mr. Saccone in a hangar at the Pittsburgh airport.

Mr. Nagel, who sells air-treatment products to the manufacturing sector, doesn’t buy arguments from business that tariffs will hurt the economy by pushing prices higher. “I think the average U.S. person is willing to pay an extra five or six cents for a can of beer to have jobs in the U.S.,” he said.

Story continues below advertisement

Mr. Trump’s protectionism clashes with his own party’s free-trade orthodoxy, but was a key part of his formula for eking out victories in once solidly Democratic manufacturing states. And labour activists here are simultaneously supportive of the policy and anxious that it will drive their natural constituency toward the GOP.

“We’re hopeful. We’ve been wanting tariffs,” said Lynda Nathenson, a 58-year-old activist with the United Steelworkers. “But I’m skeptical of the timing, announcing it right before the election. I am a little bit worried that it’s going to push people to the other side.”

The actual effect of the policy, meanwhile, is an open question. Nationalists argue that pushing out foreign competitors will help domestic industry. Free traders counter that pushing up the prices of steel and aluminium will hurt companies that use those metals in their products and damage the overall economy.

Even some of Mr. Trump’s supporters concede that the President is more concerned with the jobs of the past than the future.

Mike Simpson, a 55-year-old respiratory therapist and Trump supporter, points to Pittsburgh’s success diversifying its economy as the steel industry collapsed. The bustling city is now as known for its medical research and tech sectors as it is for manufacturing.

“It’s adapted over time. I don’t think steel is going to do much for Pittsburgh’s future,” Mr. Simpson said. “We got away from steel. It’s a whole different market.”

Story continues below advertisement

Still, the political imperative is paramount. Even as voters headed to the polls in the 18th congressional district, Canadian Foreign Minister Chrystia Freeland rushed to Washington for talks with Trump administration officials and members of Congress aimed at pushing NAFTA forward and winning a permanent exemption from tariffs. The day before, Mr. Trump pressed Prime Minister Justin Trudeau in a phone call on agreeing to a NAFTA deal.

And Mr. Trump’s party was determined to avoid the implications of losing a Rust Belt seat mere months before defending its congressional majority: The national GOP poured more than US$10-million into the race, five times the federal Democrats’ spending.

But the race also reveals a conundrum for Mr. Lamb’s party: How to win back conservative, blue-collar Democrats who were once part of their base without alienating the party’s progressive wing – or pandering to outright bigotry.

Eugene Barno, a retired coal miner and once-loyal Democrat, said he left the party to support Mr. Trump in 2016 in part because of the billionaire’s promises to revive the coal and steel industries – and in part because he was repelled by the Democrats’ social liberalism.

“It seemed the Democrats were more aligned with the illegals and the gays and everybody except us,” Mr. Barno, 71, said as he walked into a weekend rally for Mr. Lamb at a county fairground in a rural stretch of the district.

Just as the President has straddled ideological divides to win in Pennsylvania, Mr. Lamb mixed right- and left-wing views in unusual ways to fight back. A tall, telegenic, 33-year-old ex-Marine and federal prosecutor, he is simultaneously pro-gun, anti-abortion and tough on crime, but favours unions, public education and other social programs.

Story continues below advertisement

In his victory speech, he invoked the spirit of Franklin Delano Roosevelt and praised organized labour.

“These unions have fought for decades for wages benefits, working conditions, basic dignity and social justice. Thank you,” he said.

Mr. Saccone himself has a strong résumé: A seasoned state legislator, college professor and former Air Force counterintelligence officer, he lived in North Korea as a monitor for an ill-fated deal to dismantle Pyongyang’s nuclear weapons program. But he proved an uninspiring campaigner, and his support for right-to-work legislation put him at odds with blue-collar voters.

Chris Bonneau, a political scientist at the University of Pittsburgh, said the President’s appeal in western Pennsylvania is more than purely economic. And he sees a connection between the economic nationalism and the emotive social issues that animate the President’s base.