Canada’s 78-day election campaign, which ends Monday, took an ugly turn last month thanks to the machinations of Prime Minister Stephen Harper. Harper’s gambit appears to have backfired, but in the process it has shaken Canadians’ particular sense of exceptionalism: the notion that we belong to an unusually kind and welcoming society.

For much of August and September, the country’s major parties had been locked in a three-way tie. Two out of three voters told pollsters they wanted to defeat Harper, the leader of the Conservative Party, but they were divided between two center-left parties: Opposition Leader Tom Mulcair’s New Democratic Party (the NDP) and Justin Trudeau’s Liberals.

Then a Canadian court decision gave Harper what he took to be an opportunity.

Four years ago, the Harper government forbade immigrant Muslim women from wearing face coverings like the niqab during citizenship ceremonies. The ban affected a vanishingly small group. Of the 700,000 people admitted to Canadian citizenship since 2011, only two have declined to uncover their faces for the required oath of allegiance to the queen. One sued the government, and in September, the Federal Court of Appeal upheld her right to wear religious headgear during the oath-taking—after unveiling in private to verify her identity. Harper pounced on the decision; his deputies promised an appeal to the Supreme Court of Canada, and the prime minister hammered the issue during a September 24 French-language debate in Montreal, Quebec.

“When we join the Canadian family, we should not hide our identity,” Harper declared. “Never will I say to my daughter that a woman has to cover her face because she’s a woman.” Mulcair, for his part, accused Harper of attempting to “hide his record”—particularly on the flailing economy—“behind a niqab.”

The location of these comments was telling. Quebec’s determination to retain its French language and culture has made it fertile ground for nativism. Its previous Parti Québécois government sought to ban the use of conspicuous religious symbols by civil servants (the “conspicuous” qualifier allowed for small crosses, but excluded burkas, turbans, and yarmulkes), and to require citizens seeking services from them to keep their face uncovered. Quebec is also the NDP’s stronghold, a source of more than half the party’s seats in the last parliament. By exploiting hostility against Muslims, Harper could undermine Mulcair’s commanding lead in Quebec. Sure enough, the New Democrats’ support in Quebec dropped sharply during the last two weeks of September.

That same month, Harper’s campaign recruited the Australian election strategist Lynton Crosby, who has been accused of using dog-whistle appeals to anti-immigrant sentiment to, among other things, help engineer the British Conservative Party’s recent electoral victory. Encouraged by the shifting polls, Canada’s Conservatives piled on, announcing a police tip line citizens could call to snitch on neighbors’ “barbaric cultural practices.” The prime minister mused about banning civil servants from wearing Muslim head coverings.

A government-commissioned poll last March showed overwhelming public disapproval of women wearing the niqab during citizenship ceremonies. But disapproval is one thing; the specter of bureaucrats compelling women to remove clothing quite another. Canadians still like to think of themselves as tolerant and welcoming. By picking on an unpopular religious minority—Muslims constitute just 3.2 percent of Canada’s population—the government provoked widespread outrage. The Globe and Mail called the government’s tack a “culture war fabricated to take voters’ minds off the real and complex issues in this election.” The Toronto Star accused Harper of “relentlessly fanning hostility toward Muslims.” Canadians dismayed by the bigotry flocked to the sarcastic hashtag #BarbaricCulturalPractices to denounce everything from wearing socks with sandals to Harper’s refusal to investigate the cases of 582 missing and murdered aboriginal women in the country.

Sabotaging NDP support in Quebec had unintended consequences for the Conservatives. The NDP’s declining poll numbers signaled to anti-Harper voters that Liberal Justin Trudeau, son of Canada’s late Prime Minister Pierre Trudeau, was the better bet for defeating the current government. Trudeau outperformed Harper in a foreign-policy debate in late September, coming across not as the flaky naïf portrayed by the prime minister, but rather as a cheerful, energetic young man facing off against “two old grumps,” as one commentator put it. In the final days of the campaign, Trudeau’s Liberals have pulled ahead of the Conservatives and far ahead of the New Democrats, with some supporters of the latter apparently decamping to the more promising Trudeau. (The Liberals also suffered a setback this past week when Trudeau’s campaign co-chair resigned, after the disclosure of an email in which he advised an energy company on how to lobby Canada’s next government.)

Justin Trudeau’s father is remembered for two accomplishments: establishing Canada’s Charter of Rights and Freedoms, a bill of rights that courts have used to strike down many Conservative-passed laws; and implementing a constitutionally entrenched policy of multiculturalism, a doctrine that celebrates the inclusion of such diverse groups as—oh, say—women who choose to wear the niqab.

As I wrote in The Atlantic last month, many Canadians are embarrassed by Harper’s policies, particularly his disregard for parliamentary norms and suppression of government information. His attack on Muslim women takes this dismay to a new level. When Harper accuses niqabists of “hiding their identity,” he is wrong on two counts. As he well knows, they are required to unveil in private to a female citizenship officer prior to the public ceremony. But in a larger sense, they are not hiding but flaunting their identity—obdurately insisting their adopted country live up to its promise of welcoming those who are neither “old-stock” Anglos nor pure laine Québécois.

That a prime minister thought he might salvage his flagging reelection fortunes by promoting fear of such determined women will play on Canada’s conscience long after the votes have been counted.