ʿAli happened to stay behind the Prophet ﷺ and (did not join him) during the battle of Khaibar for he was having eye trouble. Then he said, "How could I remain behind Messenger of Allah ﷺ?" So ʿAli set out following the Prophet ﷺ , When it was the eve of the day in the morning of which Allah helped (the Muslims) to conquer it, Messenger of Allah ﷺ said, "I will give the flag (to a man), or tomorrow a man whom Allah and His Apostle love will take the flag," or said, "A man who loves Allah and His Apostle; and Allah will grant victory under his leadership." Suddenly came ʿAli whom we did not expect. The people said, "This is ʿAli." Messenger of Allah ﷺ gave him the flag and Allah granted victory under his leadership.
عَنِ النَّبِيِّ ﷺ فِي خَيْبَرَ وَكَانَ بِهِ رَمَدٌ فَقَالَ أَنَا أَتَخَلَّفُ عَنْ رَسُولِ اللَّهِ ﷺ فَخَرَجَ عَلِيٌّ فَلَحِقَ بِالنَّبِيِّ ﷺ فَلَمَّا كَانَ مَسَاءُ اللَّيْلَةِ الَّتِي فَتَحَهَا اللَّهُ فِي صَبَاحِهَا قَالَ رَسُولُ اللَّهِ ﷺ لأُعْطِيَنَّ الرَّايَةَ أَوْ لَيَأْخُذَنَّ الرَّايَةَ غَدًا رَجُلاً يُحِبُّهُ اللَّهُ وَرَسُولُهُ أَوْ قَالَ يُحِبُّ اللَّهَ وَرَسُولَهُ يَفْتَحُ اللَّهُ عَلَيْهِ فَإِذَا نَحْنُ بِعَلِيٍّ وَمَا نَرْجُوهُ فَقَالُوا هَذَا عَلِيٌّ فَأَعْطَاهُ رَسُولُ اللَّهِ ﷺ فَفَتَحَ اللَّهُ عَلَيْهِ