The Battle of Ahzaab (coalitions) or Khandaq (trench), which took place in the 5th year after hijrah, was indeed very trying and difficult for the Muslims. The key factor behind this battle was that following the banishment of the Banun Nadheer, a Jewish tribe, from Madeenah Munawwarah, Huyayy bin Akhtab went to Makkah Mukarramah in order to incite the Quraish to fight against Rasulullah (sallallahu ‘alaihi wasallam). Meanwhile, Kinaanah bin Rabee’ approached the Banu Ghatafaan tribe and persuaded them to do the same and even promised to give them half the produce of Khaibar annually. Thus, a coalition force of 10 000 disbelievers came to Madeenah Munawwarah with the intention of wiping out the Muslims once and for all. (Fat-hul Baari vol. 7, pg. 499)
When Rasulullah (sallallahu ‘alaihi wasallam) heard of their coming, he consulted the Sahaabah (radhiyallahu ‘anhum) as to what should be done. Sayyiduna Salmaan Faarsi (radhiyallahu ‘anhu) suggested that a trench be dug around Madeenah Munawwarah, in order to protect it from the invading army. This suggestion was accepted and the Sahaabah (radhiyallahu ‘anhum) set out to dig this trench in very difficult conditions.
When the disbelievers reached, they laid siege to Madeenah Munawwarah and surrounded it. To make matters worse, the Banu Quraizah, a Jewish tribe living in Madeenah Munawwarah who had a treaty with the Muslims, broke their treaty and sided with the disbelievers. The nights were also bitterly cold and the Muslims were starving for a few days. (Tabaqaat Ibni Sa’d vol. 2, pg. 66 and Seerah Ibni Hishaam vol. 2, pg. 220) This siege lasted for the duration of fifteen days to a month (according to different reports) and was thus a very trying time for the believers. (Subulul Huda war Rashaad vol. 4, pg. 397)
Allah Ta‘ala describes this scenario in the Quraan Majeed in the following words,
إِذْ جَآءُوكُم مِّن فَوْقِكُمْ وَمِنْ أَسْفَلَ مِنكُمْ وَإِذْ زَاغَتِ ٱلْأَبْصَٰرُ وَبَلَغَتِ ٱلْقُلُوبُ ٱلْحَنَاجِرَ وَتَظُنُّونَ بِٱللَّهِ ٱلظُّنُونَا۠ ﴿١٠﴾ هُنَالِكَ ٱبْتُلِىَ ٱلْمُؤْمِنُونَ وَزُلْزِلُوا۟ زِلْزَالًا شَدِيدًا ﴿١١﴾
“Remember when the enemy came upon you from above (outside) and from beneath you (within), and when the eyes were dazzled (with fright) and the hearts reached the throats (in horror) and you were thinking about (the help of) Allah all sorts of thoughts. There, the believers were tested and they were powerfully shaken.” (Surah Ahzaab v10-11)
Sayyiduna Abu Sa‘eed Khudri (radhiyallahu ‘anhu) explains that during the battle of Khandaq they asked Rasulullah (sallallahu ‘alaihi wasallam), “Is there anything we could read (to drive the enemy away) for indeed the hearts have reached the throats (i.e. we are experiencing severe fear and fright).” In response to this, Rasulullah (sallallahu ‘alaihi wasallam) replied in the affirmative and taught them the following du‘aa,
اَللّٰهُمَّ اسْتُرْ عَوْرَاتِنَا وَآمِنْ رَوْعَاتِنَا
“O Allah, conceal our shortcomings and eliminate the source of our fear.” (Musnad Ahmad #10996)
During these days, on one occasion, Rasulullah (sallallahu ‘alaihi wasallam) waited for the sun to move from its zenith. He then addressed the Sahaabah (radhiyallahu ‘anhum) saying, “Do not desire to encounter the enemy, rather ask Allah for ease. But if you do encounter them, then be patient. And know that Jannah lies beneath the shadows of the swords.” Rasulullah (sallallahu ‘alaihi wasallam) thereafter made the following du‘aa:
اَللّٰهُمَّ مُنْزِلَ الْكِتَابِ ، وَمُـجْرِيَ السَّحَابِ ، وَهَازِمَ الْأَحْزَابِ ، اِهْزِمْهُمْ وَانْصُرْنَا عَلَيْهِمْ
“O Allah, The Revealer of the book (i.e. the Quraan Majeed), The Driver of the clouds, The Defeater of the coalitions. Defeat them and assist us against them.” (Saheeh Bukhaari #3024)
Allah Ta‘ala accepted the du‘aa of Rasulullah (sallallahu ‘alaihi wasallam) and subjected the disbelievers to such a violent wind that uprooted their tents, overturned their pots and utensils and threw the disbelievers into utter confusion. In the ensuing chaos, Abu Sufyaan gave the instruction for the army to pack up and leave immediately. Thus, Allah Ta‘ala removed this severe calamity from the Muslims. (Fat-hul Baari vol. 7, pg. 511 and Subulul Huda war Rashaad vol. 4, pg. 386 & 389)