Judge Muhammad Azam Khan of the additional district and sessions court ordered the release of Rimsha Masih against two bail bonds of Rs 5 lakh each. "I accept her bail application," Khan said in a packed courtroom.
The order came following a two-and-a-half-hour hearing on Rimsha's bail petition, which was marked by noisy arguments between lawyers of both sides.
A large number of activists of civil society groups, including the NGO Avaaz, gathered at the court to express solidarity with Rimsha.
The case, which prompted concern from the West and the Vatican, also focussed attention once again on Pakistan's harsh blasphemy law, under which a person can be punished with life in prison or death.
The lawyer of the man who had accused Rimsha of burning pages of the Quran said her counsel had not submitted key documents in court.
On the other hand, the police officer investigating the case told the judge that several witnesses had testified before a magistrate that she was falsely implicated due to evidence planted by Khalid Chishti, the imam of the mosque in the low-income Mehria Jaffar neighbourhood of Islamabad.
Chishti was arrested last week after a man testified that he had seen the cleric stuffing pages of the Quran in a bag belonging to Rimsha. The bag originally contained only some other papers and ashes
Shortly after the court announced its order, Rimsha's lawyer Tahir Naveed Chaudhary said the two bail bonds would be paid by the All Pakistan Minorities Association, which has been spearheading efforts to free the girl.
Chaudhry, a Christian, is a leader of the Pakistan People's Party and a member of the Punjab assembly. He is also a leader of the All Pakistan Minorities Association.
Rights activists said it would take several hours to post the two bail bonds and complete the paperwork for Rimsha's release. The activists also expressed concern about possible threats to Rimsha even after her release.
Rimsha's family is currently in hiding due to such threats, they said.
Rimsha was arrested on August 16 after an angry mob surrounded a police station and demanded that action be taken against her. She was currently being held at the high-security Adiala Jail in Rawalpindi. Her judicial remand, which was extended last week, was to end on September 14.
An official medical board that examined Rimsha concluded that she was about 14 years old and that her mental development did not correspond to her age.
Rights groups have warned that Pakistan's controversial blasphemy law is often used to settle personal scores or persecute minorities like Christians.
Last year, Punjab Governor Salmaan Taseer and Minority Affairs Minister Shahbaz Bhatti, a Christian, were gunned down by extremists after they criticised the blasphemy law.