Voters in an Ontario by-election have meted out a harsh blow to Premier Kathleen Wynne's Liberals, handing a 25-point victory to the Progressive Conservatives in Whitby-Oshawa.

Ms. Wynne fought hard to wrest the seat from Patrick Brown's Tories – deploying a barrage of negative advertising and calling in Prime Minister Justin Trudeau to campaign in the riding – but lost in a rout.

Tory candidate Lorne Coe crushed Liberal Elizabeth Roy, 53 per cent to 28 per cent with nearly all polls reporting late Thursday evening. NDP candidate Niki Lundquist trailed with 16 per cent. The win was a huge improvement for the Tories over the past general election, when they prevailed in the riding by nine points.

Story continues below advertisement

The Premier was surprisingly upbeat as she took the stage at Ms. Roy's election-night party in an Italian restaurant in a Whitby strip plaza.

"Obviously, we would all have wanted a different outcome tonight, that's a given," she told about 200 supporters.

Ms. Wynne said she was unbowed and would push forward with her agenda of building transit, bringing in a cap-and-trade system for carbon emissions and a new provincial pension plan. And she vowed to win the riding in the next general election in 2018.

"As I was coming in, people were saying, 'In two years, in two years we can do this,'" the Premier said, flashing a victory sign. "As we build the infrastructure that we're building … as we work to tackle climate change, as we work to make sure people have secure retirements – those are all the things that we are working on right now, and that's not going to stop."

The vote came as the Liberals are in the middle of an unpopular privatization of Hydro One and reeling from criminal charges against three party members in two different scandals over the past six months.

But the Liberals seemed to genuinely believe they had a shot at taking the riding and invested heavily in their by-election effort.

Ms. Wynne aimed to capitalize on the afterglow of Mr. Trudeau's victory in the fall, in which he took the federal equivalent of the seat away from the Conservatives, and brought him to Whitby earlier in the week for a rally.

Story continues below advertisement

The Liberals also hoped that local drama in the riding would work to their advantage: The seat previously belonged to former PC deputy leader Christine Elliott, defeated by Mr. Brown in last year's leadership race. Ms. Elliott never returned to the legislature afterward and resigned her seat three months later. The Liberals appointed her the province's patient advocate, curtailing the amount of campaigning she could do in the by-election.

Ms. Wynne also tried to turn the tables on the Hydro One issue in an attack ad that ran on local radio. When the opposition parties claimed that selling Hydro One would result in higher electricity rates, the Premier accused them of wanting to bring back coal-fired power plants, which were closed two years ago.

"When anyone promises you cheaper electricity, they're really promising to burn coal again," Ms. Wynne said in the ad. Neither the PCs nor the NDP have promised to bring back coal plants.

The win is a triumph for Mr. Brown in the first serious test of his leadership, putting a feather in his cap ahead of a party conference next month.

The seat is crucial to the Tories: It is one of only two they hold in the vast expanse of suburbs around Toronto, a vote-rich area that usually decides provincial elections.

In his victory speech at a legion hall in downtown Whitby, Mr. Brown poked fun at Mr. Trudeau's intervention in the riding.

Story continues below advertisement

"It's nice to see that sunny ways have come with blue skies here in Whitby-Oshawa," he said before introducing Mr. Coe, a former civil servant and Durham regional councillor.

The NDP, for its part, went into the by-election with high hopes but came away disappointed.

The party had a strong candidate in Ms. Lundquist, a well-spoken labour lawyer with a string of big victories at the Ontario Human Rights Tribunal, and a base of blue-collar voters in the Oshawa portion of the riding. The party also invested heavily in radio ads that tried to sell itself as a more effective opposition than the PCs.