Banu Thaqif had been long standing rivals of the Quraysh. They saw the Quraysh's defeated as an opportunity to attack and seize control of Mecca for themselves.
In response, Prophet Muhammad called all Muslims to battle and led an army of 12,000 against them. Banu Thaqif's side had over 20,000.
Banu Thaqif setup an ambush in the Valley of Hunain, making most Muslims flee. However, Prophet Muhammad was able to rally the troops and counter the assault.
During the battle, some tribes had begun killing women and children, and were later strongly rebuked for it by Prophet Muhammad, formalizing the prohibition against killing non-combatants and civilian rights.
Lecture notes available at http://www.why-quran.org/?p=706.
Subscribe at http://www.why-quran.org/subscribe to watch the lectures live and participate in the Q&A at the end of each class.
Video recording of this lecture + Q&A available on YouTube at https://www.youtube.com/watch?v=GpYmvk1JQSI&list=PLpkB0iwLgfTat-Pgh4W3WFmupPamiC9UT.