In their fight to be recognized as the standard bearers of change, Mr. Mulcair, 60, and Mr. Trudeau, 43, have been hostile to each other but both have said that they would try to block Mr. Harper from forming government if the Conservatives or their own parties do not get a majority.

Mr. Trudeau took over the Liberals in 2013 when the party was in shambles after a historic rout two years earlier. By all accounts, it has been restored to a position as a serious political force. Recent polls show it in the lead.

The youngest of the main candidates, Mr. Trudeau has led a campaign of high style and tight scripts, inviting photographers to see him sparring in a boxing ring, paddling a canoe, or picking pumpkins with his wife and their three young children. He recently outlined a child welfare program in Montreal’s Olympic Stadium, saying that the arena’s seats could hold the 60,000 children who would be lifted out of poverty under the Liberal proposal. As a video drone operated by one of his aides buzzed overhead in the nearly empty stadium, he waved, smiled and boarded a bus.

His opponents have tried to use his age, relative inexperience, and youthful appearance against him. One early Conservative ad ran through a list of Mr. Trudeau’s supposed shortcomings, and concluded with the line, “Nice hair though.” Another favored punch line: “Just not ready.”

Mr. Mulcair was a bit more subtle, addressing Mr. Trudeau in debates as “Justin.”

The condescension may have backfired: Mr. Trudeau proved to be as forceful a presence as his opponents in debates that also included Elizabeth May of the Green Party, and Gilles Duceppe of the Bloc Québécois.

For his part, Mr. Mulcair, the leader of what has traditionally been Canada’s most left-leaning major party, came into the campaign as the front-runner. The party had surprised even itself by sweeping seats in Quebec in 2011.

That support was shaken when the Harper government pursued a ban on the niqab, a face veil worn by some Muslim women, during citizenship ceremonies. Many in the French-speaking region were in favor of the ban but Mr. Mulcair opposed it, saying that while he was not comfortable with the niqab, the courts had ruled against prohibiting it. The Conservatives, Mr. Mulcair charged, were using it as a “weapon of mass distraction.” Mr. Harper said the ban “reflects our values as a society.” So far, polls suggest, the niqab debate may have undermined the New Democrats in Quebec, and coincided with their loss of ground elsewhere.