فَلَمْ تَقْتُلُوْهُمْ وَلٰكِنَّ اللّٰهَ قَتَلَهُمْۖ وَمَا رَمَيْتَ اِذْ رَمَيْتَ وَلٰكِنَّ اللّٰهَ رَمٰىۚ وَلِيُبْلِيَ الْمُؤْمِنِيْنَ مِنْهُ بَلَاۤءً حَسَنًاۗ اِنَّ اللّٰهَ سَمِيْعٌ عَلِيْمٌ ( الأنفال: ١٧ )
Falam taqtuloohum wa laakinnal laaha qatalahum; wa maa ramaita iz ramaita wa laakinnal laaha ramaa; wa liyubliyal mu'mineena minhu balaaa'an hasanaa; innal laaha Samee'un Aleem (al-ʾAnfāl 8:17)
And you did not kill them, but it was Allah who killed them. And you threw not, [O Muhammad], when you threw, but it was Allah who threw that He might test the believers with a good test. Indeed, Allah is Hearing and Knowing. (Al-Anfal  : 17)
1 Mufti Taqi Usmani
So, it is not you who killed them, but in fact Allah killed them. And you did not throw when you threw but Allah did throw, so that He might bless the believers with a good favour. Surely, Allah is All-Hearing, All-Knowing.