A deal has been reached to end the uprising led by radical cleric Moqtada Sadr in the Iraqi city of Najaf.
Moqtada Sadr (right) went himself to Ayatollah Sistani's house
Iraq's most influential Shia leader, Ayatollah Ali Sistani, suggested the deal, which was welcomed by the interim government as a "great victory".
Members of Mr Sadr's Mehdi Army are set to disarm and leave the holy Imam Ali shrine by 1000 (0600 GMT) on Friday.
The pact came hours after scores died in attacks near Najaf, in the bloodiest day of the three-week stand-off.
Mr Sadr and his supporters have been challenging the rule of the interim Iraqi government and fighting US-led forces in the city.
But just hours after Ayatollah Sistani - Iraq's most revered Shia cleric - arrived in Najaf, a spokesman for the ayatollah announced the agreement.
At a hastily arranged press conference, the spokesman said negotiations were "three-quarters towards the end of this crisis".
The main points put forward by the ayatollah had been accepted by Mr Sadr, he said.
Under the deal, Mr Sadr will hand responsibility for the shrine to Ayatollah Sistani and his men will disarm.
Moqtada Sadr will hand responsibility for the Imam Ali shrine to Ayatollah Sistani
Mehdi Army will lay down their weapons and leave the shrine
Visitors will be allowed into shrine complex, and fighters will leave with them
Foreign forces will leave Najaf; Iraqi police will take control of security
Iraqi government will repair buildings destroyed by shelling
Foreign forces will leave Najaf.
The agreement was reached when Mr Sadr himself went to where Ayatollah Sistani was staying just outside the old city, though it is not known if the two men met.
It followed Ayatollah Sistani's dramatic arrival in Najaf, accompanied by thousands of supporters.
A spokesman for the interim Iraqi government said it supported the deal.
"Brothers, we have entered the door to peace," said Qassen Daoud.
He said the government had agreed that "visitors" to Najaf - taken to mean Ayatollah Sistani's supporters - would be allowed to enter the Imam Ali shrine,
where Mr Sadr's followers are holed up.
They will then leave the shrine by Friday at 1000, along with Mr Sadr's disarmed followers.
Mr Daoud said Mr Sadr's supporters would then be welcome to join the political process. He said Mr Sadr would be allowed to remain free.
The BBC's Alastair Leithead in Najaf says the deal allows everyone to save face.
It gives the Mehdi Army fighters an opportunity to blend into the crowds as they lay down their weapons and leave the shrine.
The 22-day standoff in Najaf began with clashes between US-led forces and Mr Sadr's followers close to his home in Najaf - clashes which neither side admitted initiating.
Doctors say dozens of people have been killed and hundreds injured.
US and Iraqi government forces moved closer and closer to the shrine but did not launch a direct attack on the site, which is one of the holiest for Shia Muslims.
At one stage, the Iraqi government announced that it had retaken control of the shrine complex, but that was later proved wrong.
Day of violence
The peace deal came after one of the bloodiest days in Iraq's recent past.
Iraq's health ministry said 74 people died and 315 were injured in the nearby town of Kufa, after a mortar attack on a mosque and exchanges of gunfire.
It was unclear who carried out the attacks. At least 25 were killed in the mortar attacks on the mosque, where many people believed to be supporters of Mr Sadr had gathered to march to Najaf.
It was unclear who carried out the Kufa attacks
Later, there were more deaths near Kufa as gunmen hidden among Shia marchers apparently shot at Iraqi police, who fired back.
Reuters reported a similar fatal exchange of gunfire involving supporters of Ayatollah Sistani in Najaf.
It said 15 Sistani supporters were shot dead and 65 wounded.
US-led forces said they had not carried out any operations in Kufa for 24 hours and the interim government said it had called a ceasefire in Najaf.
That ceasefire remains in place, our correspondent reports, and Najaf is quiet.