The simmering confrontation between the civilian government and the army in Pakistan has spilled into the open after the military warned that remarks this week by the prime minister had "potentially grievous consequences for the country".

The military and the government are at loggerheads over a scandal dubbed memogate, in which the former ambassador to Washington is accused of making a "treacherous" written offer to the US to rein in Pakistan's military in return for American support for the civilian government. The case, aimed squarely against the president, Asif Zardari, is before the supreme court, which appointed a judicial commission that began hearings this week.

The prime minister, Yousaf Raza Gilani, had this week described the affidavits to the court on memogate from the army chief and the head of the military's spy agency as "unconstitutional and illegal", pointedly speaking in an interview with a Chinese newspaper while the army chief was on an official tour in China, Pakistan's closest ally.

The military, in a highly unusual statement, responded, saying that "there can be no allegation more serious" levelled against the army chief, General Ashfaq Kayani, and the director general of Inter-Services Intelligence (ISI), Lieutenant General Ahmed Shuja Pasha.

"This has very serious ramifications with potentially grievous consequences for the country," the military said.

It is thought that the military is manoeuvring to remove the president, hoping the courts will force him from power. But his determination to cling on could result in another coup. There is speculation that, to head off the military's plan, the government will try to sack the army chief.

In their court written testimonies, Kayani and Pasha had pressed the judges to investigate the allegations against the former US envoy, Husain Haqqani, while the government had asked the court to drop the case and leave it to an investigation by a parliamentary committee.

The government was shocked that the military's affidavits had not been cleared by it first. In his affidavit, Pasha said that he had "seen enough corroborative material" to "prove" the allegations against the Washington ambassador, who was forced to resign over the issue.

The military insisted in its statement on Wednesday that it had "followed the book" in responding to the court proceedings.

Ikram Sehgal, an analyst and former brigadier, said the army was "seething with fury" over Gilani's comments.

"The government is trying desperately to ensure that the army tries a coup d'etat, so that they go down as political martyrs," he added.

On Wednesday the government replaced the defence secretary, Naeem Khalid Lodhi, a retired general with close links to the military, with Nargis Sethi, who is loyal to the ruling Pakistan People's party. That fuelled rumours that the government is considering changing the military's leadership, an authority that it legally possesses but which would be a highly risky move.

Attempting to cool tempers, a ­senior government minister, Khursheed Shah, said: "The army chief will complete his tenure. We don't want a clash of institutions."

The army has staged four coups in the past and democracy was only restored by elections in 2008 after the last period of military rule. Since the 2008 polls, the military and Zardari's government have been in a state of near constant tension.

The memogate case could yet lead to treason charges being filed against Haqqani, who said in an interview with the Guardian this week that he was the ­victim of a "witch-hunt" against ­democracy in the country. His accuser, the American ­businessman Mansoor Ijaz, is due to fly into Pakistan next week to testify before a judicial commission now investigating the issue.

In a separate amnesty case, the supreme court this week called the prime minister "not honest", and ordered the government to revive a corruption investigation against Zardari, relating to alleged money-laundering in Switzerland dating back to the 1990s.

The case is likely to reach a crunch point on Monday – the deadline given by the supreme court for the government to comply with its orders, concerning a presidential legal amnesty that it removed. The court has threatened to disqualify the prime minister or president in the event that the government fails to comply.