Canadians vote on Monday to determine whether Prime Minister Justin Trudeau, who swept into office four years ago as a charismatic figure promising "sunny ways", will remain in power after two major scandals.
Trudeau, 47, the Liberal Party leader, was endorsed by former Democratic 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 he was shaken during the campaign by a blackface scandal and has been dogged by criticism of his handling of a corruption case involving a major Canadian construction company.
Trudeau, the son of former Canadian Prime Minister Pierre Trudeau, has also had to overcome a sense of fatigue with his government.
His Liberals and the main opposition Conservatives led by Andrew Scheer are in a neck-and-neck race, according to opinion polls.
"The truth is it's a coin toss right now," said Ipsos pollster Darrell Bricker.
A year ago, no one would have predicted that Trudeau risked being the first prime minister since the 1930s to secure a parliamentary majority and then fail to win a second term.
The latest opinion polls suggest he may narrowly avert that result and could return to office with a minority in the 338-seat House of Commons.
That would still leave Trudeau in a weakened position and needing the support of left-leaning opposition parties. Five parties are contesting Canada's federal election to push through key pieces of legislation.
Despite Scheer's dimpled smile, Trudeau's main rival has proven to be a determined opponent. One of the defining moments of the campaign was when Scheer attacked Trudeau during the English-language debate.
"He can't even remember how many times he put blackface on, because the fact of the matter is he's always wearing a mask," Scheer said. "Mr. Trudeau, you are a phoney and you are a fraud and you do not deserve to govern this country."
In his bid to unseat Trudeau, Scheer is also promising to balance the federal budget and eliminate a "carbon tax" on fossil fuels. Scheer, 40, although a career politician, is running his first campaign as party leader after winning a bitter Conservative leadership fight in 2017.
The six-week official campaign period has been a rough and meandering ride with dirty tactics on both sides.
The liberal image of Trudeau, who has championed diversity as prime minister and whose father opened up 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 Lavalin Group Inc from corruption charges. In August, a top watchdog said Trudeau breached ethics rules.
Given the fact that neither of the front-runners could come away with a parliamentary majority, it is the smaller left-leaning New Democratic Party (NDP) or the separatist Bloc Quebecois that could end up holding the balance of power.
Only six weeks ago, both those parties looked like they were heading toward electoral disaster. But NDP leader Jagmeet Singh and the Bloc's Yves-Francois Blanchet have won praise for campaigns in which they cast themselves as alternatives to the leaders of the big parties.
"I am a lifelong Liberal voter and I am stumped on this one, mostly because I am really concerned about a Conservative win and just trying to figure out how to vote strategically," said Kristin Street, 33, a strategy manager at a computer games company in Port Moody, British Columbia.
Australian Associated Press