When the Jews of Bani Qaynqaa were expelled from Madinah because of their trouble making, their sister tribe, the Bani Nuzayr, were very angry. They became deadly enemies of Islam and waited for an opportunity to do the Muslims harm.

Once the Holy Prophet (S), together with a few companions, went to the fort of the Bani Nuzayr. While he waited outside the fort, the Jews sent one of their men to climb out from inside and kill him by throwing a huge rock on his head. The Holy Prophet (S) came to know of this treacherous scheme just in time and immediately left the place. Since the Bani Nuzayr had broken the treaty which they had signed, the Holy Prophet (S) gave them ten days to leave Madinah. After some resistance, they left Madinah, demolishing their houses so that the Muslims could not occupy them. They were allowed to take away all the possessions that they could carry, except for weapons of war. Some of them went to Syria and others settled with the Jews of Khayber.

On settling down at Khayber, the Banu Nuzayr became determined to take revenge on the Muslims. They contacted the Quraish in Makkah and 20 leaders from the Jews and 50 from Quraish signed an agreement in the Holy Ka'ba that so long as they lived, they would fight the Holy Prophet (S). Thereafter, the Jews and Quraish contacted their allies and sent agents to a number of tribes for help. In this way, 10,000 soldiers gathered. They then marched upon Madinah under the command of Abu Sufyan.

When the news of these preparations reached Madinah, the Holy Prophet (S) consulted his companions. Salman Farsi advised to dig a deep and wide ditch on the unprotected side of Madinah. This plan was accepted and the Muslims were divided into parties of 10, and each party allotted 10 yards to dig.

The Holy Prophet himself participated in this task. The ditch or moat (Khandaq) was completed in time, just three days before the forces of the enemy reached Madinah. The Muslims could gather only 3,000 men to oppose this huge army. They camped a few miles outside Madinah.

Meanwhile, the leader of Bani Nuzayr met secretly with some Jews who still lived in Madinah. He convinced them to violate the treaty which they had concluded with the Muslims. Thus, the Muslims were exposed to danger within Madinah, and the Jews began terrorising the women and children. When the Holy Prophet (S) learnt about what was happening he sent back 500 men to patrol the city.

The enemy was astonished to see the moat because it was a new thing for Arabs. They tried day and night to cross over, but each time they were repelled by the Muslim soldiers. The enemy began to shower arrows and stones at the Muslims in their frustration.

Finally, some of the Quraish's warriors - including the famous Amr bin Abdiwad - succeeded in crossing the moat at a point where it was not very wide. Amr was one of the best warriors in all of Arabia. In battle he was considered equal to 1,000 warriors. He began to challenge the Muslims to fight, but his reputation made them hesitate. Three times the Holy Prophet (S) urged the Muslims to fight Amr. Each time only Imam Ali (A) stood up. Finally, the Holy Prophet (S) allowed him to go, giving him his own sword and tying a special turban on his head. As Imam Ali (A) went to the battle field, the Holy Prophet (S) exclaimed, "The whole Faith is going to fight the whole Infidelity".

When Amr learnt who Imam's (A) identity, he refused to fight him, saying that Abu Talib had been his friend and he did not want to kill his friend's son. Imam Ali (A) told him not to be concerned about his death because if he died he would be blessed with a place in Heaven while Amr would end up in Hell.

He then reminded Amr that he had once said that if any opponent made three requests, Amr would always grant one of them. Amr agreed to this. Imam Ali (A) then invited Amr to accept Islam or to return to Makkah or to come down from his horse as Imam (A) had no horse and was on foot.

Amr agreed to the last request and came down from his horse. A fierce battle followed.

For a time, so much dust covered both warriors that nobody knew what was happening. Amr sent a murderous blow to the head of Imam Ali (A).

Although Imam Ali (A) blocked it with his shield, Amr's sword broke through and inflicted a serious cut on his head. Imam Ali (A) then struck a blow to Amr's feet which brought Amr down. Suddenly the shout of "Allahu Akbar" was heard from Imam Ali (A) as he chopped off Amr's head. The killing of Amr shocked the other warriors who had crossed the moat, and they fled away.

The battle was brought to an end because of three factors:

The Holy Prophet (S) signed an agreement of peace with some of the tribes who had gathered to fight the Muslims.

The enemy was demoralised at the death of Amr ibn Abdiwad.

The severe winter caused the enemies' horses to perish and their food was almost finished.

Finally, the Holy Prophet (S) went to the place where the Mosque of Victory (Masjid-ul-Fath) now stands, and prayed to Allah for help. A fierce storm raged which uprooted the tents of the enemies, sending their belongings flying on all sides, and causing terror in their ranks. The Makkans and Jews fled away from the battle field. This battle is known as Ahzab (Battle of the Tribes) or Khandaq (Battle of the Moat) and the Muslims emerged victorious in spite of their fewer numbers.
The Holy Qur'an says:

"O you who believe! Remember the blessing of Allah unto you when the tribes came to you. We sent upon them a strong wind and an army that you did not see. And Allah sees all that you do." Surah al-Ahzab, 33:9