By Qasim Nauman and Sheree Sardar
ISLAMABAD (Reuters) - Pakistan's military warned of "grievous consequences" from its worsening relations with the civilian government Wednesday, and Prime Minister Yusuf Raza Gilani sacked the top defense bureaucrat, as a crisis deepened in the country's leadership.
The powerful military has often been at odds with civilian leaders and has ruled the country for more than half its 64 year history as an independent state after repeated coups.
The "memogate" scandal - which erupted last year over a leaked memo seeking U.S. help preventing a coup - has brought tension between generals and politicians to the worst point since the army restored civilian rule after last seizing power in 1999.
That tension has raised fears for the stability of the nuclear-armed country, a vital if wary U.S. ally.
The memogate scandal is now being investigated by the Supreme Court. Gilani told a Chinese news website this week that the military had broken the constitution by issuing its responses to the probe without government permission.
The military denounced Gilani Wednesday for accusing it of violating the law by responding to the investigation.
"There can be no allegation more serious than what the honorable prime minister has leveled," it said. "This has very serious ramifications with potentially grievous consequences for the country."
Gilani's office said it had sacked the defense secretary, retired Lieutenant General Naeem Khalid Lodhi, for "gross misconduct and illegal action which created misunderstanding" between institutions. Lodhi was the most senior civil servant responsible for military affairs, a post usually seen as the military's main advocate in the civilian bureaucracy.
A senior military official told Reuters the latest tension was "very serious." Lodhi was replaced by cabinet secretary Nargis Sethi, who is considered close to Gilani.
If Gilani decides to dismiss the army or intelligence chiefs - arguably the two most powerful men in Pakistan - he needs the defense secretary on his side.
One senior member of the ruling Pakistan People's Party (PPP) said the government and the army were both digging in.
"The prime minister has started throwing down the gauntlet," the party member said, asking not to be identified.
However, another top PPP official later played down talk of an imminent showdown: "We've said before, we'll say it again: we don't go for a clash of institutions because in these conditions, Pakistan's people cannot afford to have the country's integrity harmed," Khursheed Shah told reporters.
Historically, the defense secretary's post has been filled on the recommendation of military chiefs, who often choose allies, usually retired generals.
"Because this one (Lodhi) is the army's guy, they may consider this an insult," said Hasan Askari Rizvi, an independent political analyst.
The military, which sets foreign and security policies, drew rare public criticism after U.S. special forces killed Osama bin Laden on Pakistani soil in a raid in May last year, an act seen by many Pakistanis as a violation of their sovereignty.
Pakistanis rallied behind the military after a November 26 NATO cross-border air attack killed 24 Pakistani soldiers on the frontier with Afghanistan, plunging already troubled ties with Washington to their lowest point in years.
By going on the offensive, civilian leaders risk inviting the wrath of an army that runs a vast business empire when it is not watching its old rival India or fighting Taliban insurgents.
"This is political adventurism on the part of the government," said Mutahir Ahmed, professor of international relations at the University of Karachi. "Instead of stabilizing and strengthening the democratic forces, the present government is following the policy of confrontation."
In another move some analysts described as ominous, the army replaced the head of a brigade known for its prominent role in coups. The military said it was a routine matter.
"A promotion can always be explained as a routine thing, but based on its timing and the way the media has been allowed to pick it up, it is a signal," said Ejaz Haider, executive director of the Jinnah Institute think tank.
The United States, the source of billions of dollars of aid, wants Pakistan's civilian leaders and generals to maintain smooth ties so they can focus on helping Washington wind down the war in neighboring Afghanistan.
Pakistan's rulers also face an array of domestic challenges -- from crippling power cuts to widespread poverty and growing public frustrations over corruption.
Army chief General Ashfaq Kayani last month dismissed coup rumors as speculation and said the army supported democracy.
The rumors started after President Asif Ali Zardari flew to Dubai for medical treatment, amid press reports he had instigated the memo against the generals. Zardari returned from Dubai after about two weeks.
The memo scandal broke three months ago when businessman Mansoor Ijaz said a senior Pakistani diplomat had asked that the memo be delivered to the U.S. Defense Department seeking help in reining in the military after the raid that killed bin Laden.
Ijaz later identified the diplomat as the then Pakistani ambassador to the United States, Zardari ally Husain Haqqani. Haqqani denied any link to the memo but resigned as ambassador.
Zardari could face impeachment proceedings if a link is established with him. But he has proven to be a survivor in the face of controversy. He spent 11 years in jail over the last two decades on corruption charges and was also accused of murder, but never convicted and denies any wrongdoing.
"Zardari aims to stay in power till the very last day," said a close associate of Zardari.
"He is a very determined man and will stick it out even though things are very volatile in Pakistan right now."
(Additional reporting by Chris Allbritton and Rebecca Conway in ISLAMABAD, Faisal Aziz in KARACHI and Amena Bakr in DUBAI; Writing by Michael Georgy; Editing by Peter Graff)