In the sixth year after migration the Prophet (S.A.W) decided to go for Hajj some fourteen to fifteen hundred people joined him. He also carried with him some seventy camels to be sacrificed. As his intention was only to perform Hajj he did not carry any arms nor allowed his companions to carry any. Ali (A.S.) was given the banner of Islam and was asked to lead the caravan. When the caravan reached Zil Haleefa the Prophet (S.A.W) changed his dress and wore the dress of a pilgrim. The Meccans on getting the news of Prophet (S.A.W)s coming decided not to allow him to enter Mecca. They started preparing themselves to fight with him. Khalid Bin Waleed was sent with two hundred people to stop the Prophet (S.A.W) outside Mecca. The Prophet (S.A.W) was resting near a wall called Hudaibia when he got the news of Khalids coming. He immediately took a pledge from his companions to fight and die than to run away. This pledge is recorded in the history as Baitur Rizwan, and those who gave the pledge are known as Ashab-us-Samra. The representative of Quraish who came to have a dialogue with the Prophet (S.A.W) advised the Prophet (S.A.W) not to precipitate the matter and go back to Madina without performing the Hajj as he could see with him such mean and treacherous people who will leave you in the battlefield and run away [Sahih Bukhari Vol II page 7]. Abu Bakr who was sitting just behind the Prophet (S.A.W) said, "Do you think we will leave the Prophet (S.A.W) in the battle front and run away" [Tabari Vol 3 page 75]. If they can come to some understanding with the Quraish some arrangement for the next year can be made.
The Prophet (S.A.W) asked Umar Ibnul Khattab to go and talk to the Meccans on his behalf. But Umar refused and said, "I am afraid if I go I will be killed, for they very well know my hatred for them and there is nobody of my tribe in Mecca who will save me from them." Then he suggested the name of Usman Ibne Affan who was from the tribe of Banu Umayya and a relative of Abu Sufian. If he goes there he will be welcomed. The Prophet (S.A.W) then sent Usman to talk on his behalf to the Meccans. When Usman entered Mecca he was given a warm welcome by the Quraish. After preliminary discussions the Quraish decided to send Suhail Bin Amr to have further discussions with the Prophet (S.A.W). Suhail came and after discussing the matter with the Prophet (S.A.W) agreed to sign a contract with the Prophet (S.A.W) on four terms:-
(1) That his agreement will be for ten years. And during these ten years the infidels and the Muslims will not fight with each other. People from either side can move freely and there will not be any restriction on their movements.
(2) The people are free to have friendly relations with either party and nobody will object to their such relationship and will be respected by the other party.
(3) The Muslims can perform the Hajj only next year and they will not carry any arms when they enter Mecca. They can of course carry them on their journey.
(4) If any person from the infidels joins the Muslims, the Muslims will have to send them back, but when a Muslim joins the infidels he will not be returned.
When these basic terms were settled the Prophet (S.A.W) asked Ali (A.S.) to reduce them in writing.
Ali (A.S.) began to write Bismillah Hir Rahman Nir Rahim (In the name of God, the Beneficent, the Merciful). When Suhail objected to this beginning and said the agreement should start with, "With Thy Name" only and not Bismillah Hir Rahman Nir Rahim. The Prophet (S.A.W) agreed and asked Ali (A.S.) to change accordingly. Ali (A.S.) cancelled the words Bismillah Hir Rahman Nir Rahim and wrote, "With Thy Name". Continuing the agreement Ali (A.S.) wrote, "...This agreement is between Mohammad (S.A.W) the Apostle of Allah and..." Suhail stopped Ali (A.S.) and told the Prophet (S.A.W) to cancel the words Apostle of Allah after his name, as they (Quraish) do not accept him as the Apostle of Allah. The Prophet (S.A.W) asked Ali (A.S.) to erase those words and write in its place Mohammad (S.A.W) Ibne Abdullah. Ali (A.S.) refused with apology and said, "After writing the words `Apostle of Allah' after thy name how can I erase them." The Prophet (S.A.W) himself erased the words, "The Apostle of Allah" from the agreement with Ali (A.S.)s aid and ordered Mohammad (S.A.W) Ibne Abdullah to be written in its place.
Two copies of this agreement were prepared and were signed by the Prophet (S.A.W) and Suhail.
Umar Ibnul Khattab was so angry with this agreement that according to his own confession, "A great doubt arose in my heart on the day the peace treaty at Hudaibia was signed. I deviated from the Prophet (S.A.W) on that day as I had never deviated from him before. I went to him and asked "Are you not the Messenger of Allah?" The Prophet (S.A.W) replied "Verily I am". I said "Are we not right and our opponents wrong?" The Prophet (S.A.W) replied "Yes, we are right". Then I said "Why should we bear this humiliation and disgrace, and return to peace in this manner". The Prophet (S.A.W) replied, "You son of Khattab, undoubtedly know I am the Messenger of Allah, and I do not do anything without His Orders. He alone is my Helper and He will see that my labour is not lost."
The treaty of Hudaibia though annoyed many Muslims like Umar it brought tremendous relief and benefits to the Muslims. They were now not tortured or harassed any more. The Muslims who were living in Mecca surrounded by infidels were safe and could think and work for their future. And for at least ten years they had not to worry for their defence or consider themselves in danger. Those Muslims of Mecca who had hidden their identity uptil now for fear of being harassed were now openly moving as Muslims. Recitation of Quran and preaching of Islam was now done openly. Taking the name of Allah in Mecca was not a crime now. The Muslims now openly invited the infidels to embrace Islam. Before the signing of this treaty the infidels did not speak to the Muslims, but now they had friendly relations with them and moved freely with them. And above all the Prophet (S.A.W) had some peace of mind and his life was not in that danger now. And due to the atmosphere of love and peace that this agreement brought in Mecca the Muslim population doubled in just two years.
After signing of the peace treaty the Prophet (S.A.W) ordered the Muslims to sacrifice the animals he had brought from Madina. But none obeyed his orders. The Prophet (S.A.W) after asking them three times to slaughter the animals he himself rose and taking the help of Ali (A.S.) sacrificed all the animals.