* Uncertainty in a nuclear-armed country
* Historic tensions between civilian leaders and generals
* U.S. needs stable Pakistan for success in Afghanistan (Adds Pentagon comments, quotes)
By Qasim Nauman and Sheree Sardar
ISLAMABAD, Jan 11 (Reuters) - Pakistan's military warned of "grievous consequences" from its worsening relations with the civilian government on Wednesday and Prime Minister Yusuf Raza Gilani fired the top defence bureaucrat as a crisis deepened in the country's leadership.
The powerful military has often been at odds with civilian leaders and has ruled Pakistan for more than half of its 64-year history as an independent state after repeated coups.
The "memogate" scandal - which erupted last year over a leaked document seeking U.S. help in 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.
Gilani's office said it sacked the defence 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.
The United States declined to speculate on the firing, with a Pentagon spokesman calling it an internal political development and saying it would not deter U.S. efforts to improve ties.
The memogate scandal is now being investigated by the Supreme Court. Gilani told a Chinese news website this week the military had broken the constitution by issuing its responses to the probe without government permission.
The military denounced Gilani on Wednesday for accusing it of violating the law by responding to the investigation.
"There can be no allegation more serious than what the honourable prime minister has leveled," it said. "This has very serious ramifications with potentially grievous consequences for the country."
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 defence 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.
But 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 defence 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 al Qaeda leader Osama bin Laden on Pakistani soil in a raid in May 2011, an act seen by many Pakistanis as a violation of sovereignty.
Pakistanis rallied behind the military after a Nov. 26 cross-border NATO 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 stabilising 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 neighbouring 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 rumours 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 Pentagon said the top U.S. military officer, General Martin Dempsey, spoke by phone with Kayani recently. Asked whether the Pentagon sought or got assurances from the Pakistani military that it was not interested in a coup, Navy Captain John Kirby, a Pentagon spokesman, said he was not aware whether the issue had been raised.
"This is a matter for Pakistani officials and government leaders there, military and civilian, to work out," he said.
The memo scandal broke three months ago when businessman Mansoor Ijaz said a senior Pakistani diplomat had asked 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 was convicted and denies any wrongdoing.
"Zardari aims to stay in power until 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, Amena Bakr in DUBAI and David Alexander in WASHINGTON; Writing by Michael Georgy; Editing by Peter Graff and John O'Callaghan)