Qur'an
Surah 2 2:251
فَهَزَمُوهُم بِإِذۡنِ ٱللَّهِ وَقَتَلَ دَاوُۥدُ جَالُوتَ وَءَاتَىٰهُ ٱللَّهُ ٱلۡمُلۡكَ وَٱلۡحِكۡمَةَ وَعَلَّمَهُۥ مِمَّا یَشَاۤءُۗ وَلَوۡلَا دَفۡعُ ٱللَّهِ ٱلنَّاسَ بَعۡضَهُم بِبَعۡضࣲ لَّفَسَدَتِ ٱلۡأَرۡضُ وَلَـٰكِنَّ ٱللَّهَ ذُو فَضۡلٍ عَلَى ٱلۡعَـٰلَمِینَ ۝٢٥١
and so with God’s permission they defeated them. David killed Goliath, and God gave him sovereignty and wisdom and taught him what He pleased. If God did not drive some back by means of others the earth would be completely corrupt, but God is bountiful to all

When the faithful party, who were few under the command of Talut, faced their enemy, who were many under the command of Jalut,
قَالُواْ رَبَّنَآ أَفْرِغْ عَلَيْنَا صَبْرًا
(they invoked: "Our Lord! Pour forth on us patience...") meaning, send down patience on us from You.
وَثَبِّتْ أَقْدَامَنَا
(and set firm our feet) meaning, against the enemy and save us from running away and from feebleness,
وَانصُرْنَا عَلَى الْقَوْمِ الْكَـفِرِينَ
(and make us victorious over the disbelieving people.)
Allah said:
فَهَزَمُوهُم بِإِذْنِ اللَّهِ
(So they routed them by Allah's leave) meaning, they defeated and overwhelmed them by Allah's aid and support. Then,
وَقَتَلَ دَاوُودُ جَالُوتَ
(and Dawud killed Jalut)
Israelite accounts claimed that (Prophet) David killed Goliath with a slingshot that he had, which he launched at Goliath causing his death.
Talut promised that whoever killed Jalut, would marry his daughter and would share his kingship and authority. He kept his promise. Later, the kingship was transferred to Prophet Dawud in addition to being granted Prophethood by Allah. So, Allah said:
وَآتَـهُ اللَّهُ الْمُلْكَ
(...and Allah gave him (Dawud) the kingdom) that Talut had and,
وَالْحِكْــمَةِ
(and Al-Hikmah) that comes with the prophethood, meaning, after Shamwil. Allah then said:
وَعَلَّمَهُ مِمَّا يَشَآءُ
(and taught him of that which He willed.) meaning, what He willed of the knowledge that He bestowed on (Prophet) Dawud.
Next, Allah said:
وَلَوْلاَ دَفْعُ اللَّهِ النَّاسَ بَعْضَهُم بِبَعْضٍ لَفَسَدَتِ الأَرْضُ
(And if Allah did not check one set of people by means of another, the earth would indeed be full of mischief.)
This Ayah indicates that if it were not for the fact that Allah checks one set of people with another, such as when Talut and the bravery of Dawud helped the Children of Israel (against Goliath), then people would have perished. Similarly, Allah said:
وَلَوْلاَ دَفْعُ اللَّهِ النَّاسَ بَعْضَهُمْ بِبَعْضٍ لَّهُدِّمَتْ صَوَمِعُ وَبِيَعٌ وَصَلَوَتٌ وَمَسَـجِدُ يُذْكَرُ فِيهَا اسمُ اللَّهِ كَثِيراً
(For had it not been that Allah checks one set of people by means of another, monasteries, churches, synagogues, and Masjids, wherein the Name of Allah is mentioned much, would surely, have been pulled down.) (22:40)
Allah then said:
وَلَـكِنَّ اللَّهَ ذُو فَضْلٍ عَلَى الْعَـلَمِينَ
(But Allah is full of bounty to the `Alamin (mankind, Jinn and all that exists)) meaning, by His mercy and favor He fixes some of them by some others. Surely, Allah has the wisdom, the supreme authority and the clear proof against His creation in all of His actions and statements.
Allah said:
تِلْكَ آيَـتُ اللَّهِ نَتْلُوهَا عَلَيْكَ بِالْحَقِّ وَإِنَّكَ لَمِنَ الْمُرْسَلِينَ
(These are the verses of Allah, We recite them to you (O Muhammad ) in truth, and surely, you are one of the Messengers (of Allah).)
This Ayah states, `These Ayat (verses) of Allah that We have narrated for you in truth conform to the exact manner that these stories have occurred and to the truth that still remain in the (Divine) Books that the scholars of the Children of Israel have and know. Allah said: O Muhammad,
وَأَنَّكَ
(you are)
لَمِنَ الْمُرْسَلِينَ
(one of the Messengers (of Allah)) emphatically stating the truth of his prophethood

(So they routed them by Allah's leave) by Allah's help (and David) the Prophet (slew Goliath) the unbeliever; (and Allah gave him the kingdom) Allah gave David sovereignty over the Children of Israel (and wisdom) understanding and prophethood, (and taught him of that which He willeth) i.e. how to make armour. (And if Allah had not repelled some men by others) as He repelled through David the evil of Goliath from the Children of Israel (the earth would have been corrupted). He says: Allah repelled from the believers, by means of the prophets, the evil of their enemies, and He repelled from those who refrained from participating in the fight for Allah's sake, by means of those who fought in His sake, the evil of their enemies. If it were not thus, the earth would have been corrupted. (But Allah is a Lord of Kindness to all the worlds) by this repelling.

EN

And they routed they broke them by the leave of God by His will and David who was among the ranks of Saul’s army slew Goliath; and God gave him David the kingship over the Children of Israel and Wisdom prophethood after the death of Samuel and Saul and the combination of kingship and prophethood had never come to anyone before him; and He taught him such as He willed of the manufacture of mail-coats and the speech of birds. Had God not repelled people some ba‘dahum ‘some’ substitutes for saying ba‘dan min al-nās ‘some people’ by means of others the earth would have surely been corrupted with idolaters defeating and slaying Muslims and mosques being destroyed; but God is bounteous to all worlds by repelling some by means of others.

EN

Verse 249: قَالَ إِنَّ اللَّـهَ مُبْتَلِيكُم بِنَهَرٍ (He said: Allah is going to test you by a
river).
The wisdom behind this test, as perceived by this humble commentator, appears to be as follows. Not difficult to imagine is the excitement created on such occasions but there are not many who would stay firm in their hour of trial. And should such a time come, the weakness shown by such people becomes contagious making others panic as well. Allah Almighty willed that such people be pruned out. This purpose was accomplished by this test, which is very appropriate, because steadfastness is necessary in fighting. So, being patient, when water is made available without asking in a state of intense thirst, is a proof of steadfastness, and dashing for water is a proof of its absence. Later on comes the unusual: Those who drank too much water became mysteriously more incapacitated. This has appeared in Ruh al-Ma'ani on the authority of Ibn Abi Haim from Ibn ` Abbas ؓ . Now the events and sayings mentioned in this story tell us that there were three kinds of people among them:
(1) The weak in faith who failed to make the grade in their hour of
trial.
(2) The perfect who fully succeeded in their trial but did feel concerned about how low they were in numbers.
(3) The most perfect who did not bother even about that.

EN

Literally ‘We favoured some above others’.