The Battle of the Trench (Arabic: غزوة الخندق, romanized: Ghazwat al-Khandaq), also known as the Battle of Khandaq (Arabic: معركة الخندق, romanized: Ma’rakah al-Khandaq) and the Battle of the Confederates (Arabic: غزوة الاحزاب, romanized: Ghazwat al-Ahzab), was a 27-day-long defense by Muslims of Yathrib (now Medina) from Arab and Jewish tribes. The strength of the confederate armies is estimated at around 10,000 men with six hundred horses and some camels, while the Medinan defenders numbered 3,000.
The largely outnumbered defenders of Medina, mainly Muslims led by the Islamic prophet Muhammad, dug a trench on the suggestion of Salman the Persian, which, together with Medina's natural fortifications, rendered the confederacy's cavalry (consisting of horses and camels) useless, locking the two sides in a stalemate. Hoping to make several attacks at once, the confederates persuaded the Muslim-allied Medinan Jews, Banu Qurayza, to attack the city from the south. However, Muhammad's diplomacy derailed the negotiations, and broke up the confederacy against him. The well-organized defenders, the sinking of confederate morale, and poor weather conditions caused the siege to end in a fiasco.
The siege was a "battle of wits", in which the Muslims tactically overcame their opponents while suffering very few casualties. Efforts to defeat the Muslims failed, and Islam became influential in the region. As a consequence, the Muslim army besieged the area of the Banu Qurayza tribe, leading to their surrender.
The defeat caused the Meccans to lose their trade and much of their prestige.