Image copyright AFP Image caption The attacks in Mumbai lasted almost 60 hours, and saw numerous public buildings and locations attacked

The alleged leader of the 2008 militant attacks on Mumbai has won an appeal against his detention in Pakistan.

Lawyers for Zaki-ur-Rehman Lakhvi said a government detention order issued last week infringed his rights, as he had been granted bail by another court.

Analysts say he could be freed as soon as the paperwork is completed.

India says a Pakistani militant group carried out the attacks, which killed 165. Pakistan has not convicted anyone suspected of planning the attacks.

Mr Lakhvi is among seven suspects who have been in jail awaiting trial for six years. Nine others have been charged in absentia.

Analysts say the decision to grant him bail came at an embarrassing time for the Pakistani government.

Pakistan's Prime Minister Nawaz Sharif recently promised to crack down on militancy after the Taliban killed 141 people at a school in Peshawar.

Image copyright AP Image caption Zaki-ur-Rehman Lakhvi has been in Pakistani custody since 2008

Analysis: Haroon Rashid, BBC Urdu

The accused won the appeal after the government failed to submit a detailed reply to the court's queries. A government lawyer sought more time, arguing officials were busy with other pressing engagements so they couldn't prepare a reply. The accused, lodged in Rawalpindi's Adiala Jail, is technically a free man until the government develops a new strategy.

The timing of the court judgment couldn't have been more awkward for the Pakistan government, which is desperately trying to send a message that it has "zero tolerance" to militancy after the Peshawar school massacre. Many fear that the suspension of the detention order limits the government's options. One last hope could be seeking help of the higher court.

Mr Lakhvi was granted bail by an anti-terror court on 18 December, but hours later the government imposed a three-month detention order and said it would appeal against the bail decision.

Mr Lakhvi's lawyers argued in Islamabad's High Court that the detention infringed his rights.

The judge accepted the arguments and quashed the detention order.

The suspect is now technically free to leave jail, but has been ordered to appear in court for every hearing concerning his case.

Mumbai attacks: 26-29 November 2008

Image copyright AFP Image caption Soldiers flooded into Mumbai during a three-day siege

Gunmen storm hotels, cafes and public buildings, shooting civilians and setting off explosions

Indian soldiers fight gun battles with militants for three days

Nine gunmen killed; one captured, tried and executed in India

Mr Lakhvi was accused of heading the militant group Lashkar-e-Taiba, which was blamed for the Mumbai attacks.

Correspondents say the charges brought against Mr Lakhvi and other suspects held in Pakistan were mainly based on a confession given by the only gunman captured alive after the attacks.

Mohammad Ajmal Amir Qasab was executed in 2012.

The attacks severely strained relations between India and Pakistan.

India has repeatedly criticised Pakistan for failing to prosecute any of the suspects, and has summoned the Pakistani high commissioner to discuss Mr Lakhvi's case.