Conservative candidate Glen Motz expressed gratitude to the Liberal prime minister after winning a federal byelection by a big margin in southern Alberta.

"I want to thank Justin Trudeau," Motz said in his victory speech Monday night in Medicine Hat-Cardston-Warner, a riding that Justin Trudeau had recently visited to support Liberal candidate Stan Sakamoto.

"The activity in our campaign absolutely spiked the day he arrived," Motz said of Trudeau.

Motz took 69.9 per cent (23,932 votes) while Sakamoto received 25.6 per cent (8,778 votes).

Lib Stan Sakamoto just stopped in to CPC hq to concede and congratulate Glen Motz. And crowd applauds. So Canadian. <a href="https://t.co/tsuhfzBKsZ">pic.twitter.com/tsuhfzBKsZ</a> —@CBCScott

And despite — or perhaps because of — a provincial NDP government, the federal NDP candidate, Beverly Ann Waege, received 353 votes (1.0 per cent) — roughly half of the votes cast for Rod Taylor of the Christian Heritage Party, who got 702 votes (2.0 per cent).

Kayne Cooper of the Rhinos got 0.6 per cent (211 votes) and Sheldon Johnston of the Libertarians.took 0.8 per cent (284 votes).

See the full byelection results

The voter turnout was 44.54 per cent.

The byelection was to fill the seat left vacant after Jim Hillyer, a Conservative, died in March at 41.

Lib Stan Sakamoto says 'we did gain some ground'; praises his team. He says PM's visit showed MedHat matters. <a href="https://t.co/MuCsxWIcoi">pic.twitter.com/MuCsxWIcoi</a> —@CBCScott

The riding, formerly known as Medicine Hat, was renamed following electoral redistribution in 2012.

Sakamoto, a local businessman, said Trudeau's visit shows that he cares for southern Alberta, noting Stephen Harper never made the trip.

He said, however, that the carbon tax was a "fear factor in people's minds."

The Liberals knew they were facing a tough battle in a province that went Conservative blue in all but five ridings in last fall's federal election.

Right-wing riding since 1972

The last MP elected in Medicine Hat who wasn't from a right-of-centre party was Bud Olson. He was originally voted in as a member of Social Credit, crossed to the Liberals and was re-elected when the party swept to power under Pierre Trudeau in 1968.

Olson lost in 1972, and the riding has been on the right of the political spectrum ever since, with MPs from the Progressive Conservatives, Reform, Canadian Alliance or Conservative parties.