Canadian Prime Minister Justin Trudeau will remain in power but with a minority government that will require the support of a smaller left-leaning party after a hard-fought election in which he was dogged by scandals.
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.
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, as the number of seats it was projected to win was down sharply from the 2015 election, 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? And I think businesses are going to be reluctant to make any moves until they get some satisfaction around that."
Minority governments in Canada rarely last more than 2-1/2 years.
NDP Leader Jagmeet Singh said he had spoken with Trudeau and vowed to "work hard to deliver on the country's priorities."
Ahead of the vote, polls showed a tight race between Trudeau and his main rival, Conservative leader Andrew Scheer. The Conservatives, who trailed on Monday with 121 seats, actually won the national popular vote, according to preliminary results.
Trudeau, 47, who has championed diversity as prime minister, was endorsed by former US 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.
US 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 the mainly French-speaking province of 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.
The Greens, who have assailed Trudeau for not doing enough to combat climate change, also made gains on Monday.
The Canadian dollar was little changed after the Liberal win, holding at near three-month highs.
"Markets don't like uncertainty so it will all depend on what coalition they can come up with and how sustainable that will become," said Greg Taylor, portfolio manager at Purpose Investments in Toronto.
"The bigger problem is it seems that Canadians have never been more divided and the next government really needs to work to correct that. Alberta is at risk of a broader separatist movement and that would be a major negative for Canada."
Two Liberal Cabinet ministers lost their seats in western Canada, including veteran Ralph Goodale, the public safety minister. Anger at Trudeau has mounted in the oil-producing region over federal environmental policies that the energy industry says will harm output.
The oil industry's top lobbying group has blamed Trudeau's policies for throttling investment in the sector, and some global energy companies have shed assets in the oil sands region of Alberta, the country's main oil-producing province.
Canada's economy, however, has been on a general upswing in 2019. The Canadian dollar has been the best-performing G10 currency this year, rising more than 4% against its US counterpart, as the economy added jobs at a robust pace and inflation stayed closed to the Bank of Canada's 2% target.
The six-week official campaign period was a rough and meandering ride with dirty tactics on both sides in the G7 country.
The liberal image of Trudeau, whose father opened the country to mass immigration, took a severe blow when pictures emerged early in the campaign of him wearing blackface in the early 1990s and in 2001.
Trudeau had already been wrestling with the fallout from accusations he pressured his justice minister to help shield engineering firm SNC-Lavalin Group Inc <SNC.TO> from corruption charges. In August, a top watchdog said Trudeau breached ethics rules.
Scheer also proved to be a determined opponent, although his hopes for a major breakthrough were dashed.
Scheer, 40, promised to balance the federal budget and eliminate a "carbon tax" on fossil fuels. He was running his first campaign as party leader after winning a bitter leadership fight in 2017.
"The Tories made a fundamental mistake by being opposed to the carbon tax," said Hugh Segal, who was chief of staff to former Conservative Prime Minister Brian Mulroney.
"I've often heard it said the worst mistake a party can make is to get sucked into its own low expectations of the population," he said.