The five-point agreement was hammered out by Qadri and an 11-member government team after five hours of talks at the site of the protest by thousands of supporters of the cleric.
The ruling Pakistan People's Party and its allies conceded most of the demands made by Qadri, including the dissolution of the National Assembly and electoral reforms.
The agreement, which was signed by Qadri, Prime Minister Raja Pervez Ashraf and the members of the government negotiating team, envisages a key role for the cleric's party, Pakistan Awami Tehreek, in electoral reforms and the appointment of a caretaker premier.
"The treasury benches, in complete consensus with Pakistan Awami Tehreek, will propose names of two honest and impartial persons for appointment as caretaker Prime Minister," the agreement said.
Qadri told his supporters that the caretaker premier would have to be chosen with "complete consensus" and his party would not be satisfied if it was only involved in consultations.
The National Assembly or lower house of parliament will be dissolved before it completes its term on March 16 so that the polls can take place within 90 days, the agreement said.
Qadri's demand for changes in the Election Commission will be discussed at a meeting between government leaders and Pakistan Awami Tehreek representatives in Lahore on January 27.
Law Minister Farooq Naek will convene a meeting of leading lawyers to discuss proposed changes to the poll panel.
A month will be given for scrutiny of nomination papers for "pre-clearance" of candidates under Articles 62 and 63 of the Constitution by the Election Commission.
No candidate will be allowed to start his campaign until he gets pre-clearance from the poll panel, the agreement said.
The agreement further said the proposed electoral reforms will focus on Qadri's demand for enforcement Articles 62, 63 and 218 (3) of the Constitution, the Representation of Peoples' Act and a Supreme Court judgement for free and fair polls.
The two sides also agreed to withdraw all cases registered against each other during Qadri's protest and to ensure there are "no acts of victimisation and vendetta". Qadri asked his supporters to disperse following the signing of the "Islamabad Long March Declaration".
Other government leaders who addressed the gathering, including Information Minister Qamar Zaman Kaira and Commerce Minister Amin Fahim, described the agreement between the two sides as a "victory for democracy".
The cleric's supporters began celebrating and shouting slogans after he announced that the two sides had reached an agreement. The talks were held inside Qadri's bulletproof container.
Footage on television showed Qadri and the government leaders, visible through the large windows of the container, engaged in hectic consultations.
Earlier in the day, Qadri extended a deadline he had set for the government to act on his demands to quit and dissolve the national and provincial assemblies after being contacted by emissaries for a dialogue.
The head of the Tehrik Minhaj-ul-Quran organisation urged his supporters not to leave till the talks were completed and a written agreement was hammered out.
He said he had set only one condition for talks ¿ that Interior Minister Rehman Malik should not be part of the government delegation.
"We will leave only after victory," he said. Qadri and his followers have been staging a sit-in near parliament since Tuesday.
Since he marched from Lahore to Islamabad with his supporters, Qadri has set several deadlines for action on his demands that have been consistently ignored by the government.
Over the past two days, there has been considerable criticism of Qadri in the media and social networking websites for bringing scores of women and children for the protest in Islamabad.
Many of the protestors have been sitting out in the cold and sleeping in the open. The ruling PPP had earlier said Qadri's demands could not be implemented without violating the Constitution.
Information Minister Kaira had pointed out that Qadri was demanding sweeping electoral rolls even though the cleric cannot himself contest polls in Pakistan as he is a Canadian national.
The PPP's efforts to stand up to Qadri received a shot in the arm yesterday after opposition parties led by the PML-N said they would oppose any unconstitutional or unlawful attempt to derail the democratic system.