BEFORE campaigning began in August for Canada’s general election, pundits speculated that the country’s centrist Liberal Party, which had governed for most of the past century, might soon fade into irrelevance. Stephen Harper, the Conservative prime minister, hoped to be elected to a fourth term. His main challenger looked like being Thomas Mulcair, leader of the left-leaning New Democrats (NDP), which had supplanted the Liberals as the official opposition but had never governed the country before. Mr Harper spent much of the campaign mocking the Liberals’ inexperienced leader, Justin Trudeau, the son of a former prime minister, as “just not ready” to lead the country.

On October 19th Canada’s voters toppled the prime minister and humbled the pundits who had predicted the Liberals’ demise. Mr Trudeau’s party won a majority of the 338 seats in the House of Commons and can govern without support from the NDP, which finished third.

The election was a referendum on Mr Harper’s divisive decade in power. As a net exporter of energy, Canada was hurt by the drop in oil prices. Its economy contracted in the first half of 2015, undermining Mr Harper’s claim that only the Conservatives could manage it. Two-thirds of voters wanted him out of office, but it was not clear they would coalesce around either of his main challengers.

In the end they swung behind Mr Trudeau, thanks to his deft campaign and to mistakes by the NDP. Mr Mulcair, fearing that the NDP would be branded tax-and-spend socialists, joined the Conservatives in promising a balanced budget. Mr Trudeau seized the opportunity to differentiate the Liberals. He promised to run deficits temporarily to pay for a C$60 billion ($46 billion) programme of infrastructure spending over ten years. That chimed with the sunny outlook of the Liberals’ campaign. Mr Trudeau, voters decided, was the better anti-Harper.

It will take something more than a cheerful disposition to cope with Canada’s problems. The commodities boom, which had shielded Canada from the worst effects of the global financial crisis, has ended, revealing economic malaise. GDP and productivity have been growing at a plodding pace, firms do not innovate enough and infrastructure is overburdened. Consumer debt and house prices are frighteningly high. Business investment and exports have yet to take over from indebted consumers as motors of economic growth. Mr Trudeau’s infrastructure-spending plan is a start, but it is not enough.

The change from Mr Harper’s prairie conservatism could be abrupt. The new prime minister plans to give the middle class a lift by cutting income taxes, which Mr Harper might have done, while raising the rate on incomes of more than C$200,000, which the Conservatives would certainly not have done. Where Mr Harper was reluctant to act on climate change, the new prime minister plans to reach agreement with Canada’s provinces on national targets for reductions in greenhouse-gas emissions. He wants to legalise marijuana and take in 25,000 Syrian refugees by the end of the year. He has promised to replace the British-style first-past-the-post voting system, though with what is not yet clear.