Hazrat Mufti Ebrahim Salejee (Daamat Barakaatuhu) mentioned:
There is nothing more efficient in warding off the punishment of Allah Ta‘ala than imaan, taubah and righteousness. Everyone and everything is in His divine control, so the correct thing is to correct the relationship with Him.
In the Battle of Badr, the hearts of the Sahaabah (radhiyallahu ‘anhum) were totally focused towards Allah Ta‘ala and they gave themselves entirely to Rasulullah (sallallahu ‘alaihi wasallam). Hence, they received the divine help and assistance of Allah Ta‘ala.