thumb|Site of the Battle of the Trench, Medina

The Battle of the Trench (), also known as the Battle of Khandaq () and the Battle of the Confederates (), was part of the conflict between the Muslims and the Quraysh. The Quraysh advanced towards the Muslims, who defended themselves in Medina by digging a trench around their settlement at the suggestion of Salman the Persian. The battle took place in 627 and lasted around two weeks, resulting in five to six casualties reported by the Muslim, and three casualties amongst the Quraysh.

The Quraysh tried to launch an attack, but soon realized they had limited military capability, being primarily merchants. This prompted them to negotiate with the Bedouins in order to get them to join the campaign. The Banu Nadir, whom Muhammad had previously expelled from Medina, were also part of this effort and offered the Bedouins half of their crops in Khaybar to persuade them to participate. They reported to have gathered a confederate force of between 7,500 and 10,000 men, including Banu Ghatafan, Banu Sulaym, and Banu Asad.

Muhammad, having learned of the impending Quraysh advance, took the advice of Salman the Persian to have his followers make a deep trench to impede the opponent's movement. When the Quraysh approached, they were unfamiliar with this tactic and struggled to get beyond the trench. Muhammad used the time to negotiate secretly with the Banu Ghatafan, sowing distrust among his opponents. After about two weeks, the weather deteriorated and the invading party withdrew.

Consequently, the Muslims besieged the Qurayza, and upon the latter's unconditional surrender, its men were killed and women and children enslaved. The battle caused the Meccans to lose their trade to Syria and much of their prestige.

Name

The battle is named after the "Trench", or khandaq, that was dug by Muslims in preparation for the battle as an act of defense. The word khandaq () is the Arabised form of the Middle Persian word kandag (; meaning "that which has been dug"). Salman the Persian advised Muhammad to dig a trench around the city. The battle is also referred to as the Battle of Confederates (). The Qur'an uses the term confederates () in to denote the confederacy of non-believers and Jews against Islam.

Background

After their expulsion from Mecca, the Muslims fought the Meccan Quraysh at the Battle of Badr in 624, and at the Battle of Uhud in 625. Although the Muslims were defeated at the Battle of Uhud, their strength was gradually growing. In April 626 Muhammad raised a force of 300 men and 10 horses to meet the Quraysh army of 1,000 at Badr, where the latter had threatened to attack. Although no fighting occurred, the coastal tribes were impressed with Muslim power. Muhammad also tried, with limited success, to break up many confederacies against Muslims. Nevertheless, he was unable to prevent the Meccan one.

The Confederates

Early in 627, the Banu Nadir met with the Quraysh. Huyayy ibn Akhtab, along with other leaders from Khaybar, traveled to swear allegiance with the Quraysh at Mecca.

The Banu Nadir began rousing the nomads of Najd. The Nadir enlisted the Banu Ghatafan by paying them half of their harvest. From the Banu Sulaym, the Nadir secured 700 men, though this force would likely have been much larger had not some of its leaders been sympathetic towards Islam. The Banu Amir, who had a pact with Muhammad, refused to join.

Other tribes included the Banu Murra, with 400 men led by Hars ibn Auf Murri, and the Banu Shuja, with 700 men led by Sufyan ibn Abd Shams. In total, the strength of the Confederate armies, though not agreed upon by scholars, is estimated to have included around 10,000 men and six hundred horsemen. In December 626 the army, which was led by Abu Sufyan, marched on Medina.

In accordance with the plan, the armies began marching towards Medina, Meccans from the south (along the coast), and the others from the east. At the same time, horsemen from the Banu Khuza'a left to warn Medina of the invading army.

Muslim defense

The men from Banu Khuza'a reached Muhammad in four days, warning him of the Confederate armies that were to arrive in a week. Muhammad gathered the Medinans to discuss the best strategy of overcoming the enemy. Meeting the enemy in the open (which led to victory at Badr), and waiting for them inside the city (a lesson learned from the defeat at Uhud) were both suggested. Muhammad became anxious about their conduct, and realised the grave potential danger the Qurayza posed. Because of his pact with the Qurayza, he had not bothered to make defensive preparations along the Muslims' border with the tribe. The Qurayza also possessed weaponry: 1,500 swords, 2,000 lances, 300 suits of armour, and 500 shields.

Muhammad sent three leading Muslims to bring him details of the recent developments. He advised the men to openly declare their findings, should they find the Banu Qurayza to be kind, so as to increase the morale of the Muslim fighters. However, he warned against spreading the news of a possible breach of the pact on the Qurayza's part, so as to avoid any panic within Muslim ranks.

The leaders found that the pact had indeed been renounced and tried in vain to convince the Qurayza to revert by reminding them of the fate of the Banu Nadir and Banu Qaynuqa at the hands of Muhammad. The findings of the leaders were signaled to Muhammad in a metaphor: "Adal and Qarah". Because the people of Adal and Qarah had betrayed the Muslims and killed them at the opportune moment, Maududi believes the metaphor means the Qurayza were thought to be about to do the same.

Crisis in Medina

Muhammad attempted to hide his knowledge of the activities of Banu Qurayza; however, rumors soon spread of a massive assault on the city of Medina from Qurayza's side which severely demoralized the Medinans.

The Muslims found themselves in greater difficulties by day. Food was running short, and nights were colder. The lack of sleep made matters worse. So tense was the situation that, for the first time, the canonical daily prayers were neglected by the Muslim community. Only at night, when the attacks stopped due to darkness, could they resume their regular worship. According to Ibn Ishaq, the situation became serious and fear was everywhere.

Muslim response

Immediately after hearing the rumors about the Qurayza, Muhammad had sent 100 men to the inner city for its protection. Later he sent 300 horsemen (cavalry was not needed at the trench) as well to protect the city. These include the traditional Muslim biographies of Muhammad, and quotes attributed to him (the sira and hadith literature), which provide further information on Muhammad's life. The earliest surviving written sira (biographies of Muhammad and quotes attributed to him) is Ibn Ishaq's Life of God's Messenger written some 120 to 130 years after Muhammad's death. Although the original work is lost, portions of it survive in the recensions of Ibn Hisham and Al-Tabari. Another early source is the history of Muhammad's campaigns by al-Waqidi (d. 823).