Prime Minister Stephen Harper's Conservatives have held a pair of seats in by-elections on Monday evening, despite a surge by the Liberals in the riding formerly held by Jim Flaherty.

The Conservatives retained both the Alberta riding of Yellowhead and the Ontario riding of Whitby-Oshawa, where Mr. Harper, his top campaign official and several MPs have each made recent appearances.

The Conservatives had 49 per cent of the vote in Whitby-Oshawa, eight per cent ahead of the Liberals, with 96 per cent of polls reporting on Monday evening. In Yellowhead, Conservative candidate Jim Eglinski had 63 per cent of the vote, more than triple his nearest rival, with ‎86 per cent of polls reporting.

Story continues below advertisement

Whitby-Oshawa was a Liberal seat until Mr. Flaherty and the Conservatives won it in 2006. Mr. Flaherty won the riding again in 2008 and 2011, when he got 58 per cent of the vote, but public opinion polls published in the past week showed the Conservatives were at risk of losing the seat to the Liberals.

In the riding, Conservative candidate Pat Perkins, a former Whitby mayor, ran against Liberal Celina Caesar-Chavannes, New Democrat Trish McAuliffe and three others.

Ms. Perkins won, though fell roughly 10 points short of Mr. Flaherty's share of the vote in 2011. The Liberals were on track to fall short in a riding they held until 2006 but roughly tripled their share of the vote as compared to 2011. The NDP's Ms. McAuliffe finished second in the 2011 election, but took just eight per cent of the vote Monday.

A Conservative spokesman said voters in both riding supported "a strong leader for the serious job of Prime Minister," Mr. Harper. "Canadian families like those in Yellowhead and Whitby-Oshawa know they're better off with our Conservative government's plan to balance the budget, lower taxes and create quality jobs," spokesman Cory Hann said in a statement.

In a speech at the Whitby-Oshawa campaign headquarters, Mr. Trudeau said the Conservative win nonetheless "proved Canadians cannot and will not be taken for granted."

Ms. Perkins won a nomination race where her rival complained of party interference, and received a special waiver to run because she bought her current party membership in July. At an all-candidates' debate last week, she cited her experience and said electing her would mean giving the riding a voice in the Conservative government. She also expressed doubts about climate-change policy, saying she believed scientists were divided on the issue.

Ms. Perkins won endorsements from many Conservatives, including Mr. Flaherty's widow and local MPP Christine Elliott. Jenni Byrne, a top official in the Prime Minister's Office who will lead the Conservatives' national campaign next year, also campaigned for Ms. Perkins in the riding. Mr. Harper made an announcement in the riding three days before calling the by-election there, and had earlier excluded Whitby-Oshawa in by-elections held in June.

Story continues below advertisement

Former Yellowhead MP Rob Merrifield, a Conservative, was first elected in 2000 and took 77 per cent of the vote in his riding in the 2011 election. He resigned in September to become Alberta's envoy to Washington. Mr. Eglinski, a former RCMP officer and municipal politician, will succeed Mr. Merrifield. The Liberals finished in second in the riding and the NDP third.

The Liberals have seen their by-election fortunes surge since Mr. Trudeau was elected as party leader in April of 2013. The Liberals have increased their share of the vote in each of the 11 by-elections held since Mr. Trudeau became leader, including Monday's results, as compared to 2011 results. Meanwhile, the Conservative share of the vote has declined in every riding as compared to 2011 results.

The Liberal bump has led the party to gain two seats in by-election votes under Mr. Trudeau – one from the Conservatives, another from the NDP. The next general election is scheduled for October, 2015.