If they are equal in both fiqh and recitation, precedence is given to the one who migrated (hijrah) earlier, for hijrah is the move from a land of disbelief to a land of Islam.
Should they be equal in recitation, fiqh, and hijrah, the oldest is preferred, because the Prophet ﷺ said, “Let the eldest among you lead.” Agreed upon. Advanced age is a virtue in Islam, and the elder is more likely to be humble and to have his supplication answered.
The basis for this hierarchy is the hadith recorded by Muslim from Abū Masʿūd al-Badri رضي الله عنه, in which the Prophet ﷺ said: “The one who is most proficient in reciting the Book of Allah should lead the people. If they are equal in recitation, then the one who is most knowledgeable of the Sunnah. If they are equal in knowledge of the Sunnah, then the one who migrated earlier. If they are equal in migration, then the eldest among them.”
Shaykh al-Islām Ibn Taymiyyah رحمه الله observed: “The Prophet ﷺ gave precedence on the basis of virtue—knowledge of the Book and the Sunnah. If they are equal in knowledge, he favored the one who outstripped the others in righteous deeds, placing the person who voluntarily excelled in a good deed—the emigrant—ahead of the one whose advantage lies in something Allah created in him, namely old age.”
There are, however, additional considerations whose possessors take priority in leading the prayer over others present, even if someone else is better qualified:
First: The resident imam of the mosque. If he is fit to lead, no one may precede him—even someone superior—unless he grants permission.