The Rambam's authoritative halakhic description of who Mashiach is and what he will accomplish: he will restore the Davidic dynasty, rebuild the Temple, gather the exiles, and usher in an era of Torah study and peace — a framework the Shelah builds upon.
הַמֶּלֶךְ הַמָּשִׁיחַ עָתִיד לַעֲמֹד וּלְהַחְזִיר מַלכוּת דָּוִד לְיָשְׁנָהּ לַמֶּמְשָׁלָה הָרִאשׁוֹנָה. וּבוֹנֶה הַמִּקְדָּשׁ וּמְקַבֵּץ נִדְחֵי יִשְׂרָאֵל. וְחוֹזְרִין כָּל הַמִּשְׁפָּטִים בְּיָמָיו כְּשֶׁהָיוּ מִקֹּדֶם. מַקְרִיבִין קָרְבָּנוֹת. וְעוֹשִׂין שְׁמִטִּין וְיוֹבְלוֹת כְּכָל מִצְוָתָן הָאֲמוּרָה בַּתּוֹרָה. וְכָל מִי שֶׁאֵינוֹ מַאֲמִין בּוֹ. אוֹ מִי שֶׁאֵינוֹ מְחַכֶּה לְבִיאָתוֹ. לֹא בִּשְׁאָר נְבִיאִים בִּלְבַד הוּא כּוֹפֵר. אֶלָּא בַּתּוֹרָה וּבְמשֶׁה רַבֵּנוּ. שֶׁהֲרֵי הַתּוֹרָה הֵעִידָה עָלָיו שֶׁנֶּאֱמַר (דברים ל, ג) "וְשָׁב ה' אֱלֹהֶיךָ אֶת שְׁבוּתְךָ וְרִחֲמֶךָ וְשָׁב וְקִבֶּצְךָ" וְגוֹ' (דברים ל, ד) "אִם יִהְיֶה נִדַּחֲךָ בִּקְצֵה הַשָּׁמָיִם" וְגוֹ' (דברים ל, ה) "וֶהֱבִיאֲךָ ה'". וְאֵלּוּ הַדְּבָרִים הַמְפֹרָשִׁים בַּתּוֹרָה הֵם כּוֹלְלִים כָּל הַדְּבָרִים שֶׁנֶּאֶמְרוּ עַל יְדֵי כָּל הַנְּבִיאִים. אַף בְּפָרָשַׁת בִּלְעָם נֶאֱמַר וְשָׁם נִבֵּא בִּשְׁנֵי הַמְּשִׁיחִים. בַּמָּשִׁיחַ הָרִאשׁוֹן שֶׁהוּא דָּוִד שֶׁהוֹשִׁיעַ אֶת יִשְׂרָאֵל מִיַּד צָרֵיהֶם. וּבַמָּשִׁיחַ הָאַחֲרוֹן שֶׁעוֹמֵד מִבָּנָיו שֶׁמּוֹשִׁיעַ אֶת יִשְׂרָאֵל [בָּאַחֲרוֹנָה]. וְשָׁם הוּא אוֹמֵר (במדבר כד, יז) "אֶרְאֶנּוּ וְלֹא עַתָּה" זֶה דָּוִד. (במדבר כד, יז) "אֲשׁוּרֶנּוּ וְלֹא קָרוֹב" זֶה מֶלֶךְ הַמָּשִׁיחַ. (במדבר כד, יז) "דָּרַךְ כּוֹכָב מִיַּעֲקֹב" זֶה דָּוִד. (במדבר כד, יז) "וְקָם שֵׁבֶט מִיִּשְׂרָאֵל" זֶה מֶלֶךְ הַמָּשִׁיחַ. (במדבר כד, יז) "וּמָחַץ פַּאֲתֵי מוֹאָב" זֶה דָּוִד. וְכֵן הוּא אוֹמֵר (שמואל ב ח, ב) "וַיַּךְ אֶת מוֹאָב וַיְמַדְּדֵם בַּחֶבֶל" (במדבר כד, יז) "וְקַרְקַר כָּל בְּנֵי שֵׁת" זֶה הַמֶּלֶךְ הַמָּשִׁיחַ שֶׁנֶּאֱמַר בּוֹ (זכריה ט, י) "וּמָשְׁלוֹ מִיָּם עַד יָם". (במדבר כד, יח) "וְהָיָה אֱדוֹם יְרֵשָׁה" זֶה דָּוִד. שֶׁנֶּאֱמַר (שמואל ב ח, יד) "וַתְּהִי אֱדוֹם לְדָוִד לַעֲבָדִים" וְגוֹ'. (במדבר כד, יח) "וְהָיָה יְרֵשָׁה" וְגוֹ' זֶה הַמֶּלֶךְ הַמָּשִׁיחַ שֶׁנֶּאֱמַר (עובדיה א, כא) "וְעָלוּ מוֹשִׁעִים בְּהַר צִיּוֹן" וְגוֹ': וְאִם יַעֲמֹד מֶלֶךְ מִבֵּית דָּוִד הוֹגֶה בַּתּוֹרָה וְעוֹסֵק בְּמִצְוֹת כְּדָוִד אָבִיו. כְּפִי תּוֹרָה שֶׁבִּכְתָב וְשֶׁבְּעַל פֶּה. וְיָכֹף כָּל יִשְׂרָאֵל לֵילֵךְ בָּהּ וּלְחַזֵּק בִּדְקָהּ. וְיִלָּחֵם מִלְחֲמוֹת ה'. הֲרֵי זֶה בְּחֶזְקַת שֶׁהוּא מָשִׁיחַ. (אִם עָשָׂה וְהִצְלִיחַ וּבָנָה מִקְדָּשׁ בִּמְקוֹמוֹ וְקִבֵּץ נִדְחֵי יִשְׂרָאֵל הֲרֵי זֶה מָשִׁיחַ בְּוַדַּאי. וִיתַקֵּן אֶת הָעוֹלָם כֻּלּוֹ לַעֲבֹד אֶת ה' בְּיַחַד שֶׁנֶּאֱמַר כִּי אָז אֶהְפֹּךְ אֶל עַמִּים שָׂפָה בְרוּרָה לִקְרֹא כֻלָּם בְּשֵׁם ה' וּלְעָבְדוֹ שְׁכֶם אֶחָד):
In the future, the Messianic king will arise and renew the Davidic dynasty, restoring it to its initial sovereignty. He will build the Temple and gather the dispersed of Israel. Then, in his days, the observance of all the statutes will return to their previous state. We will offer sacrifices, observe the Sabbatical and Jubilee years according to all their particulars as described by the Torah. Anyone who does not believe in him or does not await his coming, denies not only the statements of the other prophets, but those of the Torah and Moses, our teacher. The Torah testified to his coming, as Deuteronomy 30:3-5 states: God will bring back your captivity and have mercy upon you. He will again gather you from among the nations... Even if your Diaspora is at the ends of the heavens, God will gather you up from there... and bring you to the land.... These explicit words of the Torah include all the statements made by all the prophets. Reference to Mashiach is also made in the portion of Bilaam who prophesies about two anointed kings: the first anointed king, David, who saved Israel from her oppressors; and the final anointed king who will arise from his descendants and save Israel in the end of days. That passage Numbers 24:17-18 relates: 'I see it, but not now' - This refers to David; 'I perceive it, but not in the near future;" - This refers to the Messianic king; 'A star shall go forth from Jacob' - This refers to David; 'and a staff shall arise in Israel' - This refers to the Messianic king; 'crushing all of Moab's princes' - This refers to David as II Samuel 8:2 relates: 'He smote Moab and measured them with a line;' 'decimating all of Seth's descendants' - This refers to the Messianic king about whom Zechariah 9:10 prophesies: 'He will rule from sea to sea.' 'Edom will be demolished' - This refers to David as II Samuel 8:6 states 'Edom became the servants of David;' 'Seir will be destroyed' - this refers to the Messianic king as Ovadiah 1:21 prophesies: 'Saviors will ascend Mount Zion to judge the mountain of Esau....' If a king will arise from the House of David who diligently contemplates the Torah and observes its mitzvot as prescribed by the Written Law and the Oral Law as David, his ancestor, will compel all of Israel to walk in (the way of the Torah) and rectify the breaches in its observance, and fight the wars of God, we may, with assurance, consider him Mashiach. If he succeeds in the above, builds the Temple in its place, and gathers the dispersed of Israel, he is definitely the Mashiach. He will then improve the entire world, motivating all the nations to serve God together, as Tzephaniah 3:9 states: 'I will transform the peoples to a purer language that they all will call upon the name of God and serve Him with one purpose.'