SYDNEY (Reuters) - The junior partner in Australia’s coalition government elected as its new leader on Monday a former newspaper editor who takes over as deputy prime minister after an embarrassing sex scandal threatened a decades-old conservative alliance.

Slideshow ( 2 images )

Michael McCormack was chosen in a party-room ballot to replace Barnaby Joyce as the leader of the rural-based National Party after Joyce, who campaigned on family values, resigned over an extramarital affair with his former media secretary.

Joyce is expecting a child with his former staff member and has left his marriage of 24 years. He resisted weeks of pressure to quit but said on Friday he would resign as party leader after a new allegation of sexual harassment emerged.

Under the terms of the coalition deal with Australian Prime Minister Malcolm Turnbull’s centre-right Liberal Party, the leader of the Nationals automatically becomes deputy prime minister.

The drawn-out saga over Joyce’s extramarital affair had threatened to fracture the alliance between the Liberals and Nationals that has been in place for almost 100 years.

McCormack won the party-room vote over a single challenger, George Christensen, who had proposed breaking the alliance with the Nationals’ senior partner.

“I will honour that faith and trust and responsibility by always doing my best,” McCormack told reporters in Canberra.

The alliance suffered during a public falling-out between Turnbull and Joyce over the deputy leader’s affair. Turnbull described it as a “shocking error of judgment”, to which Joyce replied by calling Turnbull “inept”.

Turnbull pointedly did not leave Joyce as acting prime minister when he left Australia last week for meetings with U.S. President Donald Trump in Washington.

McCormack has kept a low profile in recent years but his appointment is not without controversy. He was forced to apologise for stridently homophobic comments he made in an editorial when he was running a rural newspaper in 1993.

Turnbull, also a former journalist, welcomed McCormack’s appointment.

“Our enduring and successful political partnership will continue under Michael’s leadership of the National Party,” Turnbull said in an emailed statement.

Political analysts saw McCormack’s low profile as an early obstacle before elections due by May 2019.

“It will take quite a bit of time before McCormack registers with voters in rural and regional Australia,” said Haydon Manning, a political science professor at Flinders University in South Australia.

“Turnbull doesn’t have much time before the election and he losses his best asset in Joyce, who is without doubt the best retail politician,” he said.

Joyce now moves to the backbench. Little-known outside Australia, he made international headlines in 2015 when he deported two dogs brought into Australia by U.S. actor Johnny Depp without the proper paperwork, a row that became known as the “war on terrier”.