Mishkat al-Masabih 4049
Al-Bara’ b. ‘Azib said:
God’s Messenger went to perform an ‘umra in Dhul Qa'da, but the people of Mecca refused to let him enter Mecca till he had made an agreement with them to enter (i.e. in the following year) and stay three days. Then when on writing the document they wrote, "This is what Muhammad God’s Messenger has agreed,” the Meccans said, “We do not acknowledge it, for if we knew you were God’s Messenger we would not prevent you; but you are Muhammad b. ‘Abdallah.” He replied, "I am' both God's Messenger and Muhammad b. ‘Abdallah.” He then told ‘Ali b. Abu Talib to obliterate "Messenger of God”, and when he protested, "No, I swear by God, I will never obliterate it,” God's Messenger took it, and although he did not write well, he wrote, ‘‘this is what Muhammad b. ‘Abdallah has agreed. The only weapon with which he will enter Mecca will be a sword in the scabbard; if any of its people wishes to follow him he will not take him out; and if any of his companions wishes to stay in it he will not prevent him.” Then when he entered and the appointed period elapsed they went to 'Ali and told him to tell his friend to leave them for the appointed period had elapsed. So the Prophet went out. 

(Bukhari and Muslim.)
عَن الْبَرَاءِ بْنِ عَازِبٍ قَالَ: اعْتَمَرَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ فِي ذِي الْقَعْدَةِ فَأَبَى أَهْلُ مَكَّةَ أَنْ يَدَعُوهُ يَدْخُلُ مَكَّةَ حَتَّى قَاضَاهُمْ عَلَى أَنْ يَدْخُلَ يَعْنِي مِنَ الْعَامِ الْمُقْبِلِ يُقِيمُ بِهَا ثَلَاثَةَ أَيَّامٍ فَلَمَّا كَتَبُوا الْكِتَابَ كَتَبُوا: هَذَا مَا قَاضَى عَلَيْهِ مُحَمَّدٌ رَسُولُ اللَّهِ. قَالُوا: لَا نُقِرُّ بِهَا فَلَوْ نَعْلَمُ أَنَّكَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ مَا منعناك وَلَكِنْ أَنْتَ مُحَمَّدُ بْنُ عَبْدِ اللَّهِ فَقَالَ: «أَنَا رَسُولُ اللَّهِ وَأَنَا مُحَمَّدُ بْنُ عَبْدِ اللَّهِ» . ثُمَّ قَالَ لِعَلِيِّ بْنِ أَبِي طَالِبٍ: " امْحُ: رَسُولَ اللَّهِ " قَالَ: لَا وَاللَّهِ لَا أَمْحُوكَ أَبَدًا فَأَخَذَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ وَلَيْسَ يُحْسِنُ يَكْتُبُ فَكَتَبَ: " هَذَا مَا قَاضَى عَلَيْهِ مُحَمَّدُ بْنُ عَبْدِ اللَّهِ: لَا يُدْخِلُ مَكَّةَ بِالسِّلَاحِ إِلَّا السَّيْفَ فِي الْقِرَابِ وَأَنْ لَا يَخْرُجَ مِنْ أَهْلِهَا بِأَحَدٍ إِنْ أَرَادَ أَنْ يَتْبَعَهُ وَأَنْ لَا يَمْنَعَ مِنْ أَصْحَابِهِ أَحَدًا إِنْ أَرَادَ أَنْ يُقِيمَ بِهَا " فَلَمَّا دَخَلَهَا وَمَضَى الْأَجَلُ أَتَوْا عَلِيًّا فَقَالُوا: قُلْ لِصَاحِبِكَ: اخْرُجْ عَنَّا فَقَدْ مَضَى الْأَجَلُ فَخَرَجَ النَّبِيُّ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ