Battle of Hunayn

The Battle of Hunayn (, Ghazwah Hunayn) was fought by the Islamic Prophet Muhammad and his followers against the Bedouin tribe of Hawazin and its subsection the Thaqif, in 630 CE, in the Hunayn valley, on the route from Mecca to At-Ta’if. The battle ultimately ended in a decisive victory for the Muslims, who captured enormous spoils. It is mentioned in "Surat at-Tawbah" of the Qur’an, and is one of the few battles mentioned by name in the Qur’an.
Preparations.
Background.
The Hawazins had been long-standing enemies of Meccans. They were located north-east of Mecca and their territory sat beside the trade route to Al-Hirah in Iraq. The Hawazins were allied with the Thaqifs, a Hawazin subtribe which had settled in Ta’if, a town south-east of Mecca whose trade routes ran through Hawazin territory. The alliance had engaged in several wars probably concerning trade routes between Ta'if and Mecca. Given this history they saw Muhammad as another powerful Quraishi leader who had come to lead his people. They thought among themselves that a war with Muslims was imminent and that the once-persecuted minority of Muslims had gained the upper hand against their non-Muslim Arab enemies, and they may have wanted to take advantage of the likely chaos in Mecca after the Muslim takeover. Some tribes favoured fighting him and the Muslims. Ahead of these were the tribes of Hawazin and Thaqif. According to the Muslim scholar Safiur Rahman Mubarakpuri "They thought that they were too mighty to admit or surrender to such a victory". So, they met Malik bin ‘Awf An-Nasri and made up their minds to proceed fighting against the Muslims. Malik persuaded other tribes to fight and gathered them before him. The confederation of tribes consisting of Nasr, Jusham, Sa‘ad bin Bakr, Bani Hilal, Bani 'Amr bin Amir and Bani 'Awf bin Amir gathered at Autas along with the Thaqif and Hawazin.
On that day Muhammad had twelve thousand armed soldiers under his standard. Out of them ten thousand were those, who had accompanied him from Medina and had taken part in the conquest of Mecca, and the other two thousand were from amongst Quraysh, who had embraced Islam recently. The command of this group rested with Abu Sufyan. In those days such an army was hardly found anywhere and this numerical strength of theirs became the cause of their initial defeat. It was because, contrary to the past, they prided themselves on the large number of their soldiers and ignored the military tactics and principles of war. When Muslim soldiers including the new Meccan converts who saw large number of men they said: "We shan't at all be defeated, because our soldiers far outnumber those of the enemy"
Spy.
The Hawazin and their allies, the Thaqif, began mobilizing their forces when they learned from spies that Muhammad and his army had departed from Medina to begin an assault on Mecca. The confederates apparently hoped to attack the Muslim army while it besieged Mecca. Muhammad, however, uncovered their intentions through his own spies in the camp of the Hawazin, and marched against the Hawazin just two weeks after the conquest of Mecca with a force of 12,000 men. Only four weeks had elapsed since the Muslim forces had left Medina to conquer Mecca.
Course of the battle.
On Wednesday night, the tenth of Shawwal, the Muslim army arrived at Hunain. Malik bin ‘Awf, who had previously entered the valley by night, gave orders to his army of four thousand men to hide inside the valley and lurk for the Muslims on roads, entrances, and narrow hiding places. His orders to his men were to hurl stones at Muslims whenever they caught sight of them and then to make one-man attacks against them.
When Muslims started camping, arrows began showering intensely at them. Their enemy’s battalions started a fierce attack against the Muslims, who had to retreat in disorder and utter confusion.
It is reported that only a few soldiers stayed behind and fought, including Ali bin Abu Talib, the standard bearer, Abbas bin Abdullah, Fadl ibn Abbas, Usamah, and Abu Sufyan bin al-Harith
Ibn Kathir writes that according to Ibn Ishaq, Jabir ibn Abdullah, who witnessed the battle, the Muslim army were panicked by a surprise attack from the enemy and many men fled the battlefield. However, a group of Muhajirun stood firmly and defended the Prophet on the battlefield. These men were Abu Bakr, Umar, Ali, Abbas ibn Abd al-Muttalib, Abu Sufyan ibn al-Harith, Fadl ibn Abbas, Rabi' ibn al-Harith, Usama ibn Zayd and Ayman ibn Ubayd. Ayman ibn Ubayd was killed that day whilst defending the Prophet Muhammad. 
"Come on, people! I am the Messenger of Allah. I am Muhammad, the son of Abdullah." Then Muhammad said "O, Allah, send down Your Help!", later Muslims’ returned to the battlefield. Muhammad, then picking up a handful of earth, hurled it at their faces while saying: "May your faces be shameful." Their eyes were thick with dust and the enemy began to retreat in utter confusion, according to the Muslim scholar Safi-ur-Rahman Mubarakpuri
After the enemy was defeated. About seventy men of Thaqif alone were killed, and the Muslims captured all their riding camels, weapons and cattle.
The Quran verse 9:25 was also revealed in this event according to Muslim scholars:
Some of the enemies fled, and Muhammad chased after them. Similar battalions chased after other enemies, Rabi‘a bin Rafi‘ caught up with Duraid bin As-Simmah who was an old man and killed him. Durayd was an important asset of the pagan forces due to his great number of experiences in battle and knowledge of terrain and war tactics
. This is mentioned by the Muslim jurist Tabari as follows:
Aftermath.
Because Malik ibn Awf al-Nasri had brought the families and flocks of the Hawazin along, the Muslims were able to capture huge spoils. 6,000 prisoners taken and 24,000 camels were captured. Some Bedouins fled, and split into two groups. One group went back, resulting in the Battle of Autas, while the larger group found refuge at al-Ta'if, where Muhammad besieged them. William Montgomery Watt states that Muhammad took on the role as the hero of Meccans by facing their Bedouin arch-enemies, the Hawazins and the Thaqifs of the city of al-Ta'if.
Islamic Primary sources.
The event is mentioned in the Sunni Hadith collection Sahih Bukhari as follows:
The event is also in Imam Maliks Al-Muwatta as follows: 