Behind in the polls this fall, Canadian Prime Minister Stephen Harper pulled a leaf out of a globally popular playbook and tried to divert attention away from Canada's faltering economy by injecting a hefty dose of Islamophobia into the campaign. The specific issue was a trumped-up controversy over whether Muslim women should be allowed to wear a niqab (a kind of full head covering) during official citizenship ceremonies — a topic that almost never arises in context, but that served as a stand-in for larger anxieties about Islam in Canada. And initially it worked. Harper's party rose in the polls, and his main rival fell.

But now that the polls are closed, it's clear that Harper has lost — by a wide margin — to Justin Trudeau's Liberal Party. And it seems the niqab issue played a crucial role.

A very quick introduction to Canadian politics

To understand what happened, you need to know a few basic facts about Canadian politics and society:

There are three main parties: Harper's Conservatives on the right, Trudeau's Liberals on the center left, and Tom Mulcair's NDP on the left.

The NDP is strongest in Quebec, where most people speak French and where the political culture is a bit more France-like than what you see in Anglophone Canada.

The NDP has never governed Canada, but thanks to its incredibly strong Quebec performance in the previous federal election it entered the 2015 campaign as the No. 2 party after decades stuck in No. 3.

Harper had governed Canada since 2006 and won three elections, but he was never very popular. His Conservatives ranged from 36 percent of the vote to 40 percent of the vote but became the largest party in parliament due to vote splitting.

The niqab issue hurt the NDP

The basic niqab gambit was clever.

The NDP's mission in the election was to break out of its base among Francophones and get progressively minded English speakers to abandon the Liberal Party and embrace the NDP as the true voice of change in Canada. That led Mulcair to oppose Harper on the niqab issue, as a defender of the kind of pro-multiculturalism sentiments generally found on the English-speaking left. But it was a very unpopular stance in Quebec, whose voters are left-wing on economic issues but tend to adhere to rigid, French-style ideas about secularism that often create flashpoints with Muslim communities.

By elevating the niqab issue, Harper succeeded in eroding the NDP's standing in Quebec with the party losing votes primarily to the separatist Bloc Québécois which joined Harper on the anti-niqab bandwagon.

Hurting the NDP turned out to be counterproductive

But Harper's plan backfired.

The decline of the NDP in Quebec undermined the argument that anti-Harper voters everywhere should hop on the Mulcair bandwagon. It made the Liberals look like the most effective anti-Harper vehicle, and since the Liberals are both more ideologically moderate and have a longer tradition as a major party, there are lots of Canadians who are just instinctually more comfortable with them. This allowed the Liberals to consolidate the anti-Harper vote in the giant province of Ontario as well as smaller provinces east of Quebec, greatly reducing the vote splitting that had been the key to Harper's earlier electoral triumphs.

Canada's been the same nice, polite country all along

The whole idea of winning an election with hard-edged cultural war wedge issues doesn't sound very Canadian, so there's something reassuring about knowing that it didn't work.

The larger issue is that the interaction of multi-party politics with a set of political institutions that combine first-past-the-post voting with a lack of checks and balances has created an odd situation in Canada. Harper has had a very successful career in Canadian politics without ever being especially popular or inducing the median voter to support his party. Instead, he's proven himself to be a cagey master of the art of divide and conquer (read about the 2008 proroguement crisis for a really zany example).

The strategic deployment of the niqab issue to undermine his main opponent by boosting support for Quebec nationalism was a brilliant example of it. In this case, it just happened to work too well — letting the Liberals reemerge as the main opposition party and solidifying much of the anti-Harper vote. Trudeau has promised, among other things, to reform Canada's voting system, which, if it happens, could put an end to the era in which this kind of skill is so important in Canadian politics.