Justin Trudeau is set to become Canada’s new prime minister after his Liberal Party swept to power in general elections, ending nearly a decade of Conservative Party rule.

The Liberals seized a parliamentary majority, an unprecedented turn in political fortunes that smashed the record for the number of seats gained from one election to the next.

The Liberals had been a distant third place party in parliament before this election.

Prime Minister Stephen Harper conceded defeat, ending his government’s nine-year run in power and the 56-year-old’s brand of fiscal and cultural conservatism.

Trudeau, 43, the son of former Prime Minister Pierre Trudeau, pledged to run a $7.7bn annual budget deficit for three years to invest in infrastructure and help stimulate Canada’s anaemic economic growth.

This rattled financial markets ahead of the vote and the Canadian dollar weakened on news of his victory.

Trudeau has said he will repair Canada’s cool relations with the Obama administration, withdraw Canada from the combat mission against the Islamic State of Iraq and the Levant (ISIL) group in favour of humanitarian aid and training, and tackle climate change.

Trudeau vaulted from third place to lead the polls in the final days of the campaign, overcoming Conservative attacks that he is too inexperienced to govern and to return to the prime minister’s residence in Ottawa where he grew up as a child.

“When the time for change strikes, it’s lethal,” former Conservative Prime Minister Brian Mulroney said in a television interview.

“I ran and was successful because I wasn’t Pierre Trudeau. Justin is successful because he isn’t Stephen Harper,” Mulroney added.

The Conservatives were projected to become the official opposition in parliament, with the left-leaning New Democratic Party in third.

Liberal supporters at the party’s campaign headquarters broke into cheers and whistles when television networks projected that Trudeau would be the next prime minister.

OPINION: Time for the real Canada to stand up

“A sea of change here. We are used to high tides in Atlantic Canada. This is not what we hoped for,” said Peter MacKay, a former senior Conservative cabinet minister.

The 11-week campaign was considered too close to call for nearly two months, a virtual tie between the Conservatives, Liberals and left-leaning NDP.

Trudeau, who took over a party in shambles in 2013, trailed early in the campaign, brushed off by his opponents as being more style than substance and an intellectual lightweight who was not ready for the job.

But a bold pledge to run a budget deficit and boost spending to spur the economy, as well as a positive message and his gregarious nature, helped the Liberals engineer a turnaround.

Up to 26.4 million electorates were eligible to vote in 338 electoral districts. About 3.6 million had already cast a ballot in advance voting a week ago.

Amid the issues raised during the campaign was a record influx of refugees fleeing war in Syria, a court ruling quashing a veil ban and a recession – crises that gave Canadians a chance to assess parties’ reactions in near-real time.