סימן קכט סעיף ג
כָּל הַשָּׁנָה, אוֹמְרִים בַּתְּפִלָּה, הָאֵל הַקָּדוֹשׁ, מֶלֶךְ אוֹהֵב צְדָקָה וּמִשְׁפָּט, חוּץ מִן רֹאשׁ הַשָּׁנָה עַד לְאַחַר יוֹם הַכִּפּוּרִים, שֶׁצְּרִיכִין לוֹמַר, הַמֶּלֶךְ הַקָּדוֹש, הַמֶלֶךְ הַמִֹּשְפָט. לְפִי שֶׁבְּיָמִים הָאֵלּוּ הַקָּדוֹשׁ בָּרוּךְ הוּא מַרְאֶה מַלְכוּתוֹ לִשְׁפֹּט אֶת הָעוֹלָם. אִם טָעָה וְאָמַר הָאֵל הַקָּדוֹשׁ, אוֹ שֶׁהוּא מְסֻפָּק אִם אָמַר הָאֵל הַקָּדוֹשׁ אוֹ הַמֶּלֶךְ הַקָּדוֹש, אִם נִזְכַּר תּוֹךְ כְּדֵי דִּבּוּר, אוֹמֵר הַמֶּלֶךְ הַקָּדוֹשׁ, וְאֵינוֹ צָרִיךְ לַחֲזוֹר לְרֹאשׁ, וְכֵן הַדִּין בְּהַמֶּלֶךְ הַמִּשְׁפָּט. אֲבָל אִם לֹא נִזְכַּר עַד לְאַחַר כְּדֵי דִּבּוּר, אֲזַי בְּהַמֶּלֶךְ הַקָּדוֹשׁ צָרִיךְ לַחֲזֹר לְרֹאשׁ הַתְּפִלָּה, (אֲפִלּוּ מִסְּפֵקָא), מִפְּנֵי שֶֹׁשָׁלֹשׁ הַבְּרָכוֹת הָרִאשׁוֹנוֹת נֶחְשָׁבוֹת כְּאֶחָת (כְּמוֹ שֶׁכָּתוּב בְּסִימָן יט סָעִיף ב). וַאֲפִלּוּ שְּׁלִיחַ הַצִבּוּר בַּחֲזָרַת הַתְּפִלָּה צָרִיךְ לַחֲזוֹר לָרֹאֹשׁ, וּצְרִיכִין לוֹמַר קְדֻשָּׁה שֵׁנִית. אֲבָל בְּהַמֶּלֶךְ הַמִּשְׁפָּט, אֲפִלּוּ יָחִיד, אֵינוֹ צָרִיךְ לַחֲזוֹר אֲפִלּוּ לְאוֹתָהּ בְּרָכָה, כֵּיוַן שֶׁהִזְכִּיר תֵּבַת מֶלֶךְ בִּבְרָכָה זֹאת. בְּכָל הַשָּׁנָה אִם טָעָה וְאָמַר, הַמֶּלֶךְ הַקָּדוֹשׁ, הַמֶּלֶךְ הַמִּשְׁפָּט, אֵינוֹ צָרִיךְ לַחֲזוֹר (קיח תקפב).
All through the year you say in the Shemoneh Esrei, hakeil hakadosh [the Almighty, the Holy One], and melech oheiv tzedakah umishpat [King Lover of righteousness and justice] except from Rosh Hashanah until after Yom Kippur, when you must say instead Hamelech hakadosh (the King, the Holy One) and Hamelech hamishpat (the King of Justice), because on these days the Holy One blessed is He manifests His dominion by judging the world. If, by mistake, you said Hakeil hakadosh, or if you are in doubt whether you said Hakeil hakadosh or Hamelech hakadosh; if you become aware of the error within the time needed to utter a short greeting, [Shalom Alecha Rebbe] you should say Hamelech hakadosh2This is so only if you did not yet begin the next berachah, but if you began the next berachah, even if it is still within toch kedei dibur, you must start from the beginning of Shemoneh Esrei. (Mishnah Berurah 582:7) and you need not start again from the beginning. The same law applies to Hamelech hamishpat. But, if you only became aware of it after the time needed for a short greeting, then, at Hamelech hakadosh you must repeat Shemoneh Esrei from the beginning, (even if in doubt),3However, if you are certain that you intended to say Hamelech hakadosh, and then much later you became doubtful if you actually said it or not, you need not repeat the Shemoneh Esrei. If, however, the doubt came into mind immediately after you completed Shemoneh Esrei, you must repeat the Shemoneh Esrei. (Ibid 114:38) If on Rosh Hashanah or Yom Kippur there is a doubt if you said Hamelech hakadosh, you need not repeat the Amidah, since you can assume that you said it as part of the special prayers of Yom Tov. (Ibid 582:4) because the first three berachos are considered as one (as is written in Chapter 19:2). Even the Chazzan during the repetition of the Shemoneh Esrei, must repeat from the beginning [if he did not say Hamelech hakadosh], and the kedusha must be said again. But at Hamelech hamishpat, even an individual need not repeat, even that berachah, since he mentioned the word melech "King" in that berachah. During the entire year, if you said, by mistake, Hamelech hakadosh or Hamelech hamishpat, you need not repeat the Shemoneh Esrei.
תנא דבי אליהו כל השונה הלכות בכל יום מובטח לו שהוא בן העולם הבא שנאמר הליכות עולם לו אל תקרי הליכות אלא הלכות (נדה ע"ג.)