However, the Rambam himself in the third chapter of Laws of Prayer, at the end of law 6, wrote, and this is his wording: And the Ne'ilah prayer – its time is such that he completes it close to the setting of the sun. Thus far his words. And according to this, it is clear that also in the first chapter his intention is regarding the end of the prayer, that it should be close to the setting. And if so, this is according to Rava, for it is the locking of the gates of the Heikhal, and how did he write "locking of the gates of heaven"? And it cannot be said that the Rambam holds that the locking of the gates of heaven is prior to the locking of the Heikhal (as occurred to the Taz in subsection 1), for it is explicitly explained in the Yerushalmi to the contrary, see there. Therefore, it appears that the Rambam holds that even close to the setting is called "locking of the gates of heaven," and "locking of the gates of the Heikhal" is much earlier. And this is also the opinion of our teacher, the Beit Yosef, in section 1, who wrote: The time of the Ne'ilah prayer – when the sun is at the tops of the trees, so that he completes it close to the setting of the sun. And the shaliach tzibbur must be brief in the selichot and verses in the middle of the prayer. And also, he should not draw out every single word in the Ne'ilah prayer, in the manner that he draws out in other prayers, so that he finishes before the setting of the sun. Thus far his words. (And the Magen Avraham in subsection 1 wrote that this is the end of the setting, the emergence of the stars, see there. And his words are puzzling, for he lengthily and precisely said before the setting. And if it is according to the words of the Magen Avraham, why did he not write according to the wording of the Tur? See there.)
אמנם הרמב"ם בעצמו בפרק שלישי מתפילה סוף דין ו כתב, וזה לשונו: ותפילת נעילה – זמנה כדי שישלים אותה סמוך לשקיעת החמה. עד כאן לשונו. ולפי זה מבואר דגם בפרק ראשון כוונתו על סוף התפילה, שתהא סמוך להשקיעה. ואם כן, זהו כרבי יוחנן, דהוי נעילת שערי היכל, ואיך כתב "נעילת שערי שמים"?וזה אין לומר דסבירא ליה להרמב"ם דנעילת שערי שמים הוי קודם לנעילת ההיכל (כמו שעלה על דעת הט"ז סעיף קטן א), דלהדיא מבואר בירושלמי ההיפך, עיין שם. ולכן נראה דהרמב"ם סבירא ליה דגם סמוך לשקיעה מקרי "נעילת שערי שמים", ו"נעילת שערי היכל" הוה הרבה קודם. וזהו גם דעת רבינו הבית יוסף בסעיף א, שכתב: זמן תפילת נעילה – כשהחמה בראש האילנות, כדי שישלים אותה סמוך לשקיעת החמה. וצריך שליח ציבור לקצר בסליחות ופסוקים שבאמצע התפילה. וגם אין לו למשוך בתפילת נעילה כל תיבה ותיבה, כדרך שמושך בשאר תפילות, כדי שיגמור קודם שקיעת החמה. עד כאן לשונו. (והמגן אברהם סעיף קטן א כתב דזהו סוף שקיעה צאת הכוכבים, עיין שם. ודבריו תמוהים, שהרי האריך ודקדק לומר קודם שקיעה. ואי כדברי המגן אברהם, למה לא כתב כלשון הטור? עיין שם.)