Canadian Prime Minister Justin Trudeau's Liberals held onto power after a closely fought election on Monday but were reduced to a minority government that will need the support in Parliament of a smaller left-leaning party.

The vote showed a deeply divided country with the defeated Conservatives winning the popular vote, while a resurgent separatist Bloc Quebecois made big strides in the mainly French-speaking province of Quebec.

The Liberals had won or were leading in 156 out of 338 seats in Monday's vote, according to Elections Canada. That put the Liberals far short of the 170 seats needed for a second straight majority government.

"You did it, my friends. Congratulations," Trudeau told supporters in Montreal early on Tuesday, speaking as his main opponents were giving concession speeches.

Trudeau, who took power in 2015 as a charismatic figure promising "sunny ways," saw his popularity drop over old photos of him in blackface and his handling of a corporate corruption case. He will now have to rely on the New Democratic Party (NDP) to push through key legislation.

Although the NDP had a disappointing night, with the 24 seats it had won or was leading in down sharply from the 2015 election when it won 44, the party could exercise significant influence over Trudeau's next government.

"I think a Liberal government supported by the NDP is likely going to lean farther left," said John Manley, a former Liberal finance minister who now works in the private sector.

"It raises a series of issues about what are the demands that an NDP party would make. What's the price of governing going to be? I think businesses are going to be reluctant to make any moves until they get some satisfaction around that."

NDP leader Jagmeet Singh said he had spoken with Trudeau and

told him his party would be "working hard to deliver on making sure we deliver the priorities that Canadians have."

Minority governments in Canada rarely last more than 2-1/2 years.

Ahead of the vote, opinion polls showed a tight race between Trudeau and his main rival, Conservative leader Andrew Scheer.

"Tonight we have put him on notice," Scheer said in Regina, Saskatchewan, of Trudeau. "His leadership is damaged and his government will end soon and when that time comes, we will be ready and we will win.

"We are the government in waiting," added Scheer, 40, whose party won 122 seats.

Trudeau, 47, who has championed diversity as prime minister, was endorsed by former U.S. President Barack Obama in the final stretch of the campaign and is viewed as one of the last remaining progressive leaders among the world's major democracies.

But the son of the late Liberal Prime Minister Pierre Trudeau also had to overcome a sense of fatigue with his government.

U.S. President Donald Trump, whose relationship with Trudeau has been testy at times, congratulated him "on a wonderful and hard fought victory" via Twitter.

The Bloc Quebecois saw its support jump in Quebec, the only place where the separatist party contests elections. It was elected or ahead in 32 seats, more than three times what the party won in 2015.

"Dear Quebecers, I heard your message tonight," said Trudeau, who also addressed voters in two western provinces where Liberals were shut out of seats.