OTTAWA—The rancorous Group of Seven summit in Canada this month laid bare a split between the Trump administration and its Western allies, but it produced a political boost for the host, Prime Minister Justin Trudeau.
Mr. Trudeau had been struggling in the Canadian court of public opinion for months, dragged down in part by missteps on his recent trip to India and his backing of a crude oil pipeline to the Pacific Coast.
But now, the country has rallied around the leader amid a public rift with President Donald Trump. Mr. Trump’s attacks have given the prime minister a chance to stick up for Canada—something Canadians love—as well as a political lifeline ahead of next fall’s election.
“There’s a long history of Canadians not wanting to be pushed around by the U.S.,” said Robert Wolfe, professor emeritus at the policy-studies school at Queen’s University, in Kingston, Ontario. “The U.S. is omnipresent in Canadian life. We have this long border; we watch U.S. TV shows; and we consume U.S. products. But we are our own country, and we want to make decisions in Ottawa that affect our lives.”
Before the Trump administration’s decision in late May to impose tariffs on Canadian-made steel and aluminum, Mr. Trudeau was trailing the Conservative Party in the polls for the first time since his 2015 victory, according to polling from Nanos Research. Support for his Liberal government fell to 33% in late May, Nanos said.
That was a turnaround following a long honeymoon. For the bulk of Mr. Trudeau’s first 18 months in office, polls showed his Liberal government with the backing of more than 40% of voters—seen as a pivotal threshold for controlling the legislature in Canada’s parliamentary system.
The decline was months in the making. Mr. Trudeau’s weeklong trip to India in February was widely panned for its emphasis on photo ops featuring his family in traditional Indian garb, which political analysts said was in poor taste.
Meanwhile, he managed to offend both environmentally-conscious voters and people dependent on the oil sector when for months he didn’t weigh in on a dispute over expanding the oil pipeline.
Mr. Trudeau then further angered his progressive base when he said last month that the government would take over the troubled project, at a cost of $3.5 billion.
Then came the U.S. tariffs. Mr. Trudeau was quick to blast the levies as “insulting” and “absurd” and promised retaliation. Mr. Trudeau vowed at the end of the G-7 summit that Canada “will not be pushed around” by the U.S. on trade, after Mr. Trump warned retaliation would be a “mistake.”
On Twitter, Mr. Trump fired back, calling the Canadian prime minister “meek,” “weak,” and “very dishonest.” He threatened more tariffs, this time targeting Canada’s auto sector. The attack and threat from Mr. Trump sent Mr. Trudeau’s popularity back on the upswing.
“This is a critical pivot,” said Nik Nanos, president of Nanos Research.
In the latest Nanos weekly-tracking poll, published June 26, the Liberals opened up a five-point lead over the Tories, holding on to 37% support.
“The reality is whenever the Liberal government has been focused on its domestic agenda, the numbers have floated around a lot,“ said Mr. Nanos. ”But when it comes to advancing Canadian interests with the U.S., for the Liberals it’s a clear win for Justin Trudeau.”
Whereas Mr. Trump has continued to single out Mr. Trudeau for criticism at rallies, Mr. Trudeau has tried to stay above the fray since the G-7 summit.
“I think my approach on the [U.S.-Canada] relationship has been very much aligned with what Canadians expect of me. You know, be firm about defending Canadian values and Canadian interests, but always look to have a constructive relationship that will benefit Canadians and the nature of our closely integrated economies,” Mr. Trudeau said on June 20.
Larry Deters, a 74-year-old retired government worker from Regina, Saskatchewan, said he generally supports the left-leaning New Democratic Party. But if an election were held today, amid the trade uproar, Mr. Deters said Mr. Trudeau would have his vote.
“If it would have been me, I would have gone after Trump and called him what I think he is, whereas Trudeau has handled him like a gentleman. But at the same time he didn’t back down. That was big for me,” Mr. Deters said.
Other polls, however, point to political risks for Mr. Trudeau. A poll by Ipsos Global Public Affairs found that 72% of Canadians approve of Mr. Trudeau’s handling of the Trump attacks, but that 55% believed that hardball from Mr. Trudeau was dangerous.
The election this month of a populist, right-leaning premier in Ontario, the country’s biggest province, also suggests disapproval of the type of progressive policies Mr. Trudeau’s administration has favored, such as carbon levies and higher taxes on the wealthy.
Mr. Trudeau also needs a successful renegotiation of the North American Free Trade Agreement when he faces the electorate next year, even with the current boost in the polls, said Richard Nimijean, a politics professor at Ottawa’s Carleton University.
“He’s got a patriotic blip, but it’s not deep,” said Mr. Nimijean. “The problem he faces is that if Nafta is terminated, he’s politically in trouble. He’s invested so much in Nafta, what are the alternatives? Our eggs are in the American basket, and Trump knows this and will exploit this.”
Write to Paul Vieira at paul.vieira@wsj.com