PRAGUE (Reuters) - Czech President Milos Zeman will appoint former Microsoft executive Ivan Pilny as finance minister next week, the president’s spokesman said on Friday, ending a row that threatened to collapse the government months before an election.

Czech President Milos Zeman delivers a speech on Plenary Session of High-Level Dialogue, at the Belt and Road Forum in Beijing, China May 14, 2017. REUTERS/Kenzaburo Fukuhara/Pool

Prime Minister Bohuslav Sobotka had tried for weeks to oust the incumbent finance minister, billionaire businessman Andrej Babis, over allegations he dodged taxes.

Babis, who founded the centrist ANO party, consistently denied any wrongdoing and refused to leave. He found an ally in President Milos Zeman, who at first refused to accept his dismissal.

Babis eventually backed down and proposed Pilny, 72, now a leading ANO lawmaker, as his replacement this week. Two days after the prime minister said he accepted Babis’ pick the president did too.

“It can be expected that the appointment will take place next week,” presidency spokesman Jiri Ovcacek said on social media.

The crisis pitted Sobotka against Zeman, who under the constitution is responsible for the replacement of cabinet ministers. Sobotka had been considering a constitutional complaint against the president for delays and imposing conditions on the change of personnel.

“I welcome that the Castle has reacted today at last to my repeated call to uphold the Constitution and I hope that President Zeman will continue to act in accordance with the rules,” Sobotka said on Facebook.

The row has been the most serious to hit the three-party coalition government that came to power in 2014 and had been seen as the most stable cabinet in 15 years. Its time in power has been marked by economic growth, record low unemployment and the first budget surplus in two decades.

Sobotka had insisted Babis’s replacement must not be too closely tied to the outgoing minister so as to allow for an impartial investigation of the tax allegations.

Babis has called the scandal a political ploy ahead of October elections. His ANO party, founded by him in 2011, holds a double-digit lead over the Social Democrats in opinion polls.