Al-e-Imran (The House of Imran) - Chapter 3: Verse 152
"Allah did indeed fulfil His promise to you when you, with His permission, were about to annihilate your enemy, until you flinched and fell to disputing about the order, and disobeyed the Prophet after Allah had brought you in sight of what you covet. Among you were some that hankered after this world and some that desired the hereafter. Then Allah did divert you from your foes in order to test you, but He forgave you: for Allah is full of grace to those who believe."
The promised help for Muslims is not unconditional. It could never be assumed that no matter how they behave or conduct themselves, they would still be victorious. This help is subject to the Muslims not being slack in fulfilling their obligations, and avoiding disagreement in respect of obeying the commandments of Allah and His messenger. This help will come provided they do not love worldly goods and pleasures over and above their life in the hereafter.
Since Allah is most forgiving and compassionate, He does not punish the Muslims even if they are found lacking in this respect or have some of these weaknesses in them. In such a case, He puts them through various tests and trials to cleanse them of their weaknesses so that they can qualify for and enjoy Allah's most bounteous help and support. This is clearly manifested in His dealing with them. This in itself is a yet another form of Allah's forgiveness and grace in dealing with them, as pointed out at the end of the verse which says: "Allah is full of grace to those who believe."
With respect to the battle of Uhud, we may note here that almost all the historians and biographers are agreed that the initial attack of the Muslims was highly successful. They had almost overrun their enemy when a detachment of theirs stationed to guard the hilltop passage in their rear with clear instructions from the Prophet, peace be upon him, not to leave their places under any conditions, abandoned their posts and joined in collecting war booty. Only a few of them were left behind. The enemy took advantage of this situation and attacked the Muslims with such ferocity from the rear that the Muslim army was totally confounded. The verse refers to this incident.
"Pondering Over The Qur'an: Surah ali Imran" - Amin Ahsan Islahi