ISLAMABAD, Sept 5 (Reuters) - Weeks of mounting anti-government protests in Pakistan had been enough to convince five of the powerful army's 11 Corps Commanders that it was time for them to step in and force embattled Prime Minister Nawaz Sharif to resign.

According to a minister close to military circles, top generals met in the garrison city of Rawalpindi at the end of August as demonstrations raged in nearby Islamabad. Thousands of protesters had just tried to storm Sharif's residence.

At the tense, four-hour conclave, Pakistan's democratic process was once again in peril, with the military pondering another intervention in a country that has seen power change hands more often through coups than elections.

But army chief Raheel Sharif decided the time was not right to overthrow the civilian leadership, and moved to quell any disagreement in his ranks by overruling the hawks and declaring the crisis must be solved through politics, not force.

Soon afterwards, the army issued a brief statement, reaffirming its commitment to democracy, and the threat of a coup, at least for now, had passed.

The minister, who declined to be named due to the sensitivity of discussing the inner workings of the military, said at least five generals had been pushing for weeks for the army to take a more "active role" in defusing the crisis.

"The time for the army to be neutral is over," was how the minister summed up the message from dissenters around the table.

Two military sources confirmed this version of events. They, like the minister, spoke on condition of anonymity.

A senior security source added: "Raheel Sharif is not interested in direct intervention. The tanks aren't going to come rolling in. This army believes in compromise."

"What comes out from the army is ultimately one opinion," he said. "And ... they have supported democracy."

BIDING HIS TIME?

General Sharif, who is not related to the prime minister, may simply be biding his time.

If, with the help of tacit military support, Nawaz Sharif does manage to ride out twin protest movements led by cricketer-turned-opposition leader Imran Khan and activist cleric Tahir ul-Qadri, he is expected to emerge a diminished figure.

It would allow the armed forces to assume greater control of policy areas they most covet - security and foreign policy - and leave it to civilians to face public anger over internal problems such as a faltering economy and widespread power cuts.

A government insider told Reuters in August that Sharif had been assured by the military he would not be asked to step down and that there would be no coup. But in return his government would have to "share space" with the army.

Under the agreement, Sharif would be subservient to generals on issues he had wanted to handle himself - the fight against Taliban militants, relations with arch-foe India and Pakistan's role in neighbouring Afghanistan after NATO combat troops withdraw at the end of 2014.

The army chief's cautious stance may have been linked to the strong show of support for the prime minister this month in parliament, where politicians lined up to back him.

General Sharif also inherited the current team of commanders from his predecessor when he took over the top job last year, making him less secure of his position, insiders said.

But with five top security officials due to retire next month, he has a chance to appoint his own men.

"It's hard to imagine an army chief trying to actively intervene or do something drastic when he isn't 100 percent sure his team will back him," said a defence ministry source.

"Next month ... he will have four of his own Corps Commanders. He'll have his own intelligence chief. Then he'll be a man to watch out for."

Spy chief Zaheer-ul-Islam, one of the five departing officers, was among those pushing for the prime minister's ouster, according to three senior government sources.

"It is not the army but elements within the ISI that have been backing Imran to get rid of Nawaz," said one of the sources, referring to Pakistan's most powerful security body, the military's Inter-Services Intelligence agency.

A senior ISI official said: "It is baseless to say the ISI is involved, but the fact is that this government has not delivered. No one will support it unconditionally."

Khan, who like Qadri accuses the prime minister of rigging the 2013 election and demands that he steps down, denies acting on anyone's orders.

HOPE QUICKLY FADED

A year ago, few would have predicted that Nawaz Sharif would be in such trouble.

Back then, he had just swept to power for a third time in a milestone poll that marked nuclear-armed Pakistan's first transition from one elected government to another.

But in the months that followed, Sharif, who crossed swords with the army in the past, moved to enhance the influence of the civilian government in a country ruled by the military for more than half of its brief and turbulent history.

Sharif further irked the generals by putting former military head and president Pervez Musharraf, who ended Sharif's last stint in power in a 1999 coup, on trial for treason.

His principle goals were to improve trade relations with India, convince Afghanistan that Pakistan would not meddle in its affairs and find a negotiated peace settlement with Islamist Taliban insurgents fighting against his rule.

But with the more conservative-minded military back in the driving seat, it would be much harder for Sharif to deliver on the rapprochement with India that he promised Indian officials when he won the election.

It could also affect how Pakistan emerges from a regional tussle for influence in Afghanistan once the majority of foreign soldiers serving there return home.

"Nawaz is the biggest loser here," said a government official. "Coup or no coup, the democratic transition has been badly disrupted." (Writing By Mehreen Zahra-Malik; Editing by Mike Collett-White)

We welcome comments that advance the story through relevant opinion, anecdotes, links and data. If you see a comment that you believe is irrelevant or inappropriate, you can flag it to our editors by using the report abuse links. Views expressed in the comments do not represent those of the Thomson Reuters Foundation. For more information see our Acceptable Use Policy.

In a camp for displaced Rohingya Muslims residents frequent bamboo “internet huts” where they can communicate with relatives who left the country, escaping the violence that led to 200 deaths and left over 140,000 homeless in 2012