TORONTO — For Canadian Prime Minister Justin Trudeau, winning a plurality of the seats in Parliament after a bruising federal election campaign was hard. Maneuvering a minority government in a deeply divided country will probably be harder.

The six-week campaign and the election Monday laid bare cleavages between left and right, between rural and urban, and between regions of the country.

Trudeau’s Liberals performed well in Atlantic Canada but captured just 17 seats west of Ontario. The oil-producing western provinces of Alberta and Saskatchewan, long Conservative strongholds, shut out the Liberals. French-speaking Quebec experienced the resurgence of the separatist Bloc Québécois, which more than tripled its representation in Parliament.

Bridging those chasms and tamping down on polarization will be a critical test for Trudeau’s government.

With most of the vote counted on Tuesday, the Liberals had won 157 seats in the House of Commons, more than any other party but shy of the 170 needed for a majority, a setback that leaves them reliant on the support of smaller parties to stay in power.

Andrew Scheer’s Conservatives edged out the Liberals in the popular vote but trailed with 121 seats. Trudeau became the first prime minister in decades to win the election while losing the popular vote; Scheer said the Conservatives had put Trudeau “on notice” — and were ready to take over when his government falls.

The challenge is clear. Minority governments in Canada have seldom lasted longer than 18 months, and rarely has the country been so polarized.

“The prevailing mood in the country is pessimistic,” said Darrell Bricker, chief executive of the polling firm Ipsos Public Affairs in Toronto. “There is a significant group of people that aren’t happy about what happened. Couple that with the geography, and you could have a combustible situation.”

“Strains of regionalism have existed for a long time in Canada,” said Daniel Beland, director of the Institute for the Study of Canada at McGill University in Montreal. “But they are re-emerging at the federal level.”

On Tuesday, it was unclear which parties the Liberals would turn to as partners in a minority government, or how they would try to govern. Precedent suggests that Trudeau will seek the support of the other parties to pass bills on a case-by-case basis.

That could pose a conundrum: Gaining the support of the smaller parties might require him to make compromises that further alienate the people who turned their backs on him in this election.

In an election night speech to supporters in Montreal, Bloc Québécois leader Yves-François Blanchet, whose party rode a wave of Quebec nationalism to capture 32 seats Monday, called on all the parties — Liberal, Conservative, the Bloc, New Democrat and Green — to work together “despite the deep divisions that we see in the electoral map.”

But then he laid down a few red lines. His party would not support any attempts to put a pipeline through the province. And it would always defend its efforts to enshrine secularism within Quebec, including the controversial provincial law that bans some public-sector workers from wearing religious symbols such as hijabs or yarmulkes on the job.

Trudeau, who represents a riding in Montreal, has refused to rule out challenging that law, which many outside Quebec oppose, potentially teeing up a future conflict.

Analysts said Trudeau doesn’t necessarily need to rely on support from Blanchet’s party to advance his agenda. A more likely ally would by Jagmeet Singh’s left-leaning New Democrats, which won 24 seats.

But that could create a challenge in oil-rich Alberta and Saskatchewan, where anger over falling oil prices because of pipeline bottlenecks and the Liberal government’s energy policies are inflaming a level of grievance and regional alienation not seen in decades. Those provinces are challenging the Trudeau government’s nationwide levy on carbon in court.

Singh’s NDP has called for more urgent action on climate change. The party opposes some pipeline projects, including Trudeau’s Trans Mountain pipeline, which oil producers and Conservative lawmakers argue is critical to the energy industry, the region and the nation.

“The NDP will push the Liberals even further left on environmental policy, which could generate even more regional resentment in oil-producing provinces,” Beland warned.

In his victory speech in a Montreal convention center on Tuesday morning, Trudeau promised that his government would “fight for all Canadians.”

“Know that you are an essential part of our great country,” he said to Alberta and Saskatchewan. “I heard your frustration and I want to be there to support you.”

But he extended the olive branch while Scheer was in the middle of his concession speech in Regina, Saskatchewan — he had flouted the convention of waiting for the other leaders to concede before launching into his victory speech.

The optics weren’t great.

“There’s a hell of a lot of anger out here right now,” said Duane Bratt, a political scientist at Mount Royal University in Alberta. “I think Trudeau ignores this at his peril.”