Image copyright AFP Image caption Mr Musharraf hoped to fight elections, but has been under arrest for months

A Pakistani court has granted bail to former military ruler Pervez Musharraf over the 2007 army operation to oust militants from Islamabad's Red Mosque.

The court approved bail on condition Mr Musharraf pay bonds totalling $2,000.

BBC correspondents say he has now been bailed in all the cases against him, which makes it likely he will be released from house arrest.

But the former general remains on a government exit control list and cannot leave the country.

Speaking outside the court in the capital, his lawyer said Mr Musharraf had no intention of leaving Pakistan.

The operation ordered by Gen Musharraf on the besieged Red Mosque left a cleric and more than 100 others dead, and fuelled a deadly militant insurgency inside Pakistan which rages to this day.

The bail granted to Pervez Musharraf paves the way for his release from custody nearly seven months after he was first arrested. At the time, one criminal case after another was lodged against him, and the Supreme Court also explored ways of trying him for high treason. But there was also speculation that the army, of which he was chief until 2008, would not allow him to be convicted as a criminal. Legal experts say there was no evidence linking him directly to any of the offences for which he was charged. The only case in which he could have been pinned down - the high treason case - failed to take off due to a lack of interest by the government. Unless he is charged with a fresh offence, he cannot be kept in detention or banned from travelling abroad. The question is, will he opt to leave the country, which most elements in the government and the army would like him to do, or stay on to try to carve a political future for himself?

Earlier this year, he returned to Pakistan from self-imposed exile to fight elections - which were won by Nawaz Sharif, the man he ousted in his 1999 coup - but swiftly ran into trouble.

He was barred from running in the general election, and was placed under house arrest in April in the first of a series of cases relating to his time in power from 1999-2008.

He faces murder trials over the assassination of former PM Benazir Bhutto and Baloch tribal leader Nawab Akbar Bugti. He has also been charged over his attempt to sack the higher judiciary in 2007.

Mr Musharraf has been bailed in all three of those cases.

Separately, the Sharif government said in June that it planned to try him for treason - but a formal complaint in that case has still to be lodged.

Mr Musharraf insists all the charges against him are politically motivated.

His house arrest is unprecedented in a country which has been ruled by the military for more than half of its history.

The latest bail ruling means Mr Musharraf could soon be free to move around Pakistan.

But he is likely to remain under guard at his villa on the outskirts of Islamabad because of threats to his life.