Justin Trudeau’s Liberal Party has retained power but a narrow election win means he is forced to lead a minority government as prime minister.
His party will claim the most seats in parliament but their second term will be much harder, relying on other parties to pass legislation.
The Liberals are expected to claim 156 seats, 14 short of a majority.
His centre-right Conservative rivals are heading for 122 seats, a marked increase from the 95 it held before.
Monday night’s results could be good news for the country’s left-leaning New Democratic Party (NDP) and its leader Jagmeet Singh, who could be kingmaker.
This federal election was seen as a referendum on Mr Trudeau, who endured a bumpy first term, tainted by scandal.
“You did it my friends. Congratulations!” he told cheering supporters in Montreal.
Turning to address those across the country who voted for him, he said: “Thank you for having faith in us to move our country in the right direction.”
And to those who did not back him, he promised his party would govern for everyone.
His weakened grip on power is being seen as a rebuke of his record but the result is bitterly disappointing for Conservative leader Andrew Scheer.
His party is expected to win the popular vote but failed to translate that support into seats.
Why has Trudeau’s popularity fallen?
Mr Trudeau swept into power in 2015 promising “real change” and a slew of progressive pledges.
Now, after four years in power, Mr Trudeau has faced criticism for his ability to follow through.
His environmental record, for example, has been undercut by his support for the Trans Mountain oil pipeline expansion project.
And Mr Trudeau’s vow to institute federal electoral reform was quickly abandoned, angering some left-leaning voters excited by the prospect of seeing an alternative voting system
Still, according to an independent assessment by two dozen Canadian academics, Mr Trudeau has kept – fully or partially – 92% of these promises, the most by any Canadian government in 35 years.
An ethics scandal early this year, known as the SNC-Lavalin affair, took a major toll on his support.
Last month an ethics watchdog found the prime minister had violated federal conflict of interest rules by improperly trying to influence a former minister in relation to a criminal trial facing major Canadian engineering firm SNC-Lavalin.
Mr Trudeau’s election odds then seemed at risk when images of the prime minister wearing blackface make-up in three separate instances were widely circulated.
The images were seen as a major hit to Mr Trudeau’s cultivated political image, characterised by compassion and inclusion.
At Trudeau’s victory party
By Jessica Murphy, Montreal
The mood is joyful if not jubilant in the Liberal election night headquarters in Montreal, where a growing crowd of supporters are cheering results showing Liberal wins as they come up on the big screens.
They may not have their majority but the Liberals are on track to win the most seats – and projections currently suggest it’s not as close a race between the Liberals and Conservatives as some polls had suggested.
As one young supporter, Adam Steiner, 18, told the BBC, a minority scenario is “not great” but at least the party “kept the Conservatives out of power”.
What does this mean for Justin Trudeau?
If he does form a minority government it’ll mean compromises, since his Liberals will need the support of other parties if he wants to hold onto power.
How has election night unfolded so far?
Early returns pointed to trouble for Mr Trudeau. His sweep of the Atlantic region was quickly upended, with Conservative and New Democratic wins in the east.
But while the Liberals did not repeat their 2015 landslide, they still made a strong showing in the Maritimes and have a tight grip across Ontario – Canada’s most populous province.
A key minister, Ralph Goodale, lost his seat in Regina, Saskatchewan after 26 years in Parliament.
Mr Goodale’s loss is one of many for the Liberals across the Prairie region. If current predictions hold, there will be no Liberal-held ridings between Winnipeg and the British Columbia Lower Mainland.
But the bigger disappointment will be felt by Mr Scheer, who pitched himself to Canadians as the candidate speaking up for issues which directly affect voters’ lives and wallets.
But instead he faced scrutiny over where the Conservative Party stood on gay marriage and abortion.
Minority governments are not uncommon in Canada – there have been three in the past 15 years.
A coalition government, however, is rare. It was last attempted in 2008 by the Liberals and NDP, but was disbanded when then-Prime Minister Stephen Harper, a Conservative, prorogued Parliament.
What’s the reaction been like?
Though he failed to claim power, Mr Scheer said he was “incredibly proud” of the larger Conservative team going to Ottawa.
“Let’s remember this feeling, coming close but falling just short,” he said.
Speaking from his home district in Burnaby, British Columbia, NDP Leader Mr Singh acknowledged some disappointing results but focused on the future.
“When we get back to Ottawa, every single day that we’re in Parliament, New Democrats are going to be working hard to make sure your life is better, that Canadians’ life is better, that peoples’ lives are better,” he said.
This election saw Mr Singh’s party slide behind Quebec’s separatist party, the Bloc Quebecois, in seats won.
US President Donald Trump also weighed in, congratulating Mr Trudeau on a “hard fought victory”.