Pakistan's government agreed on Monday to reinstate Iftikhar Chaudhry as Chief Justice to defuse a political crisis and end a street agitation that was threatening to turn into violent confrontation.
Chaudhry became a cause celebre after being dismissed in late 2007 by then-President and army chief General Pervez Musharraf.
"I announce the restoration of all deposed judges including Mr Iftikhar Chaudhry according to a promise made by the President of Pakistan and myself," Prime Minister Yousaf Raza Gilani said.
Chaudhry will be reinstated on March 21, he added.
Earlier a government official had told Reuters that along with Chaudhry's reinstatement "there will also be a constitutional package".
Opposition leader Nawaz Sharif had thrown his support behind the protest campaign by anti-government lawyers that had threatened to bring turmoil to Pakistan as the government struggles to stem militancy and to revive a flagging economy.
President Asif Ali Zardari, who was elected by parliament six months ago, had feared Chaudhry could wage a vendetta against Musharraf that could also threaten his own position.
His retreat on the issue will raise inevitable question marks over his future, while it will enhance the reputation of his chief rival, former prime minister Sharif.
Several hundred jubilant lawyers and activists gathered outside Chaudhry's Islamabad residence, which he refused to vacate after his dismissal when Musharraf declared emergency rule in a desperate move to extend his presidency for another term.
They danced and chanted "Long live the chief justice".
"He has to forget the past. He has to forget the conduct of those who were apparently against him as well as us," retired judge Tariq Mehmud, a leader of the lawyers' campaign, told Reuters.
"It's victory for those who fought for independence of judiciary and it's the first time in the history of Pakistan that a movement launched by middle class has proved successful."
The political crisis gripping the Muslim nation has alarmed the United States and Britain, which fear any slide into chaos would help the Taliban and al Qaeda become stronger in Pakistan.
Western diplomats had tried to make Zardari pull out of a collision that could destabilise the year-old civilian coalition and force a reluctant army chief, General Ashfaq Kayani, to intervene.
Sharif, a two-time Prime Minister with a conservative, religious nationalist support base, had backed a lawyers' movement fighting for the independence of the judiciary.
His government was overthrown by Musharraf in 1999, and since his return from exile in late 2007 he has become Pakistan's most popular politician, thanks partly to his stand over the judge.
Zardari finally conceded as the opposition leader and the lawyers held a day of protest in Lahore on Sunday, and set off for Islamabad for the climax of a series of protests they had dubbed "the Long March".
To stop them driving into Islamabad, authorities positioned containers and trucks across roads outside the capital.
The government had been offering concessions earlier, but Sharif refused to accept anything less than Chaudhry's restoration.
Sharif latched onto Chaudhry's cause two years ago, but the current crisis began when Zardari ejected the PML-N from power in Punjab last month, after the Supreme Court barred Sharif and his younger brother Shahbaz from holding elected office.
The constitutional package being worked out was expected to include the formation of a commission to review judicial appointments and the lifting of central government rule in Punjab, setting the stage for the provincial assembly to elect a chief minister.
Zardari, widower of assassinated former prime minister Benazir Bhutto, was elected by parliament last September after forcing Musharraf to quit the presidency.
Deeply unpopular, Zardari's image was further damaged when he broke a public promise to Sharif last year to reappoint Chaudhry, though he reappointed most other judges axed by Musharraf.