STELLARTON, Nova Scotia (Reuters) - Canadian Justice Minister Peter MacKay announced his resignation on Friday, the second shock departure from Prime Minister Stephen Harper’s cabinet this year, just months ahead of a tough election for the governing Conservatives.

Canada's Justice Minister Peter MacKay takes part in a cabinet swearing-in ceremony at Rideau Hall in Ottawa in a July 15, 2013 file photo. REUTERS/Chris Wattie/files

MacKay, citing personal reasons, said he will not seek re-election in October but will remain justice minister until then.

The departure of MacKay, 49, is the latest setback for Harper, who is in a tight three-way race with opposition parties in the run-up to October’s election.

“For entirely personal reasons, the time has come for me to step back from public life and concentrate on my young, growing family,” MacKay said after a warm introduction from Harper.

Foreign Affairs Minister John Baird resigned unexpectedly in February. The latest exit from Harper’s nine-year-old government prompted political cartoons of rats leaving a sinking ship.

“It’s a perception issue now for Harper,” said University of Calgary political science professor Anthony Sayers.

“He needs to steady the ship and, of course, resist the interpretation that these are people leaving because things aren’t looking good for the Conservatives.”

MacKay, a member of Parliament from Nova Scotia, was previously defense minister and foreign affairs minister, and was the face of a tough new security law Harper introduced this year. The Conservatives have touted their security credentials as a key campaign platform ahead of the election.

Harper and MacKay were both hawks on the war in Afghanistan and on the current Canadian engagement in the fight against Islamic State. They also moved in lockstep to ratchet up the power of intelligence agencies after two attacks on Canadian soil last year.

Polls show a tough-on-security stand and Harper’s economic leadership are strong points for the Conservatives. But their popular support has waned as voter fatigue has set in, and victory in October is far from assured.

In May, the long-dominant Conservative government in oil-rich Alberta, Harper’s home province, was thrown out of office by a surge of support for the left-wing New Democratic Party.

Analysts said the combination of MacKay’s young family and the unlikelihood that Harper will step aside to make room for a new leader were probably behind MacKay’s move.

“It has been clear for a while that Harper is not stepping down; it could be (MacKay and Baird) each had a thought they had a crack at becoming leader,” said University of Toronto political science professor Nelson Wiseman.

Harper, 56, is considered more right wing than MacKay and has maintained strict control over his government, leaving cabinet ministers little room to assert themselves.

Harper will also have to persuade voters there is room in the party for centrists after the departure of MacKay and Baird, who were considered to be on the progressive wing.

A former senior Conservative official said MacKay may focus on his young family now, and then return to politics later when the party is ready to move closer to the center of the political spectrum.

“He is going to get out and make money and six or seven years down the road, when people want more of a progressive Conservative government, he’ll be there,” said the official, who declined to be named.

While MacKay’s departure removes a potential rival to Harper, it also deprives the party of one of its most popular figures. MacKay’s cheerful easy-going nature, always happy to plunge into a crowd and shake hands, has contrasted with Harper’s more reserved demeanor.

Introducing MacKay on Friday, Harper spoke unusually warmly for more than 10 minutes about his achievements. It was in contrast to Baird’s resignation, which the prime minister was said to have learned of on television.

A member of a powerful political family in Nova Scotia, MacKay was elected to federal office at age 31 and is one of the founders, with Harper, of the modern Conservative Party. They led the 2003 merger of two right-wing parties that had split the conservative vote. The united party went on to election victory in 2006.