Both Shiʿi and Sunni sources report that when the Prophet returned from his ‘farewell pilgrimage’ (ḥijjat al-wadāʿ) on 18 Dhū al-Ḥijja 10H/16 March 632 CE, he asked the people to halt for congregational prayer. Then he took ʿAlī’s hand and lifted him to his feet to stand next to him and said:
“O people, know that what Aaron was to Moses, ‘Ali is to me, except that there shall be no prophet after me, and he is my wali to you after me. Therefore, he whose master (mawla) I am, ‘Ali is his master.”
Then he lifted up ʿAli’s arm and said:
“O God, be affectionate to him who is devoted to ‘Ali, show enmity to him who is his enemy, give victory to him who helps ‘Ali and forsake him who forsakes ‘Ali. May the truth encompass ‘Ali to the end of his life.”
Hence the use of the term walāya, or spiritual authority, as generally employed by Shiʿi Muslims in connection with ʿAli as their first Imam or any other descendant of ʿAli in the line of the imamate (for various Shiʿi groups), is rooted in the event of Ghadir Khumm.
(al-Kulaynī, 1/342–43, 349–52; Ibn Bābawayh, Man lā yaḥḍuruh, 1/229, 2/559; see also Amīnī al-Najafī, 1/12–151, 294–322).
Reference: Daryoush Muhammad Poor, Section in ʿAlī b. Abī Ṭālib entry; Encyclopedia Islamica; Vol. III https://www.academia.edu/.../%CA%BFAl%C4%AB_and_Wal%C4%81ya