The five books of the Torah contain two examples of impassioned prayers that G-d does not grant.
The first comes early on when Avraham prays on behalf of Sodom and the second comes near the end when Moshe prays to G-d to be allowed to enter Israel, and is told by that it will not happen.
Both of the prayers of these two great men were not trivial personal requests, rather urgent cries from the heart for what they considered to be their fundamental mission in life. Avraham thought that his mission was reaching the world with the message of G-d, and Moshe thought that his mission was bringing the Jewish people into Israel. Both prayers were not granted because these were not their true missions.
Avraham's true mission, despite his greatest efforts, was not to reach the world, but to bring a nation into the world. He could not save Sodom, but he could teach his son, Yitzchak, to follow in his footsteps.
Moshe's mission was not to bring the Jews into Israel. His mission was instead revealed at the very end of his life. Yet the message of his real mission appears in Vaeschanan, the very same parsha that begins with the rejection of Moshe's unfulfilled prayer, reaches its high point with the repetition of the Ten Commandments. Moshe's mission was not to bring the Jews into Israel, but into the presence of G-d.
Vaeschanan is part of Sefer Devarim, the fifth book of the Torah. And Devarim only exists because of that unfulfilled prayer.
If Moshe had gone into Israel, Devarim would not exist. It was only Moshe's recognition that he would not only die in a short time, but that he would die without being able to bring the Jews into Israel that summons up the mixture of admonishment and blessings, poetry and history that is Devarim.
Moshe is the first prophet who serves the familiar prophetic function of being sent to guide and admonish the Jewish people. Devarim creates the model that is repeated by prophets in Israel.
Even after the Jews are exiled, the prophetic legacy of Moshe endures.
Moshe's mission was not to bring the Jews into Israel, but to bring Devarim, with its prophetic model, and all of the Torah to the Jews. Had G-d granted Moshe's prayer, Devarim would not exist.
And Devarim only comes into existence at the very end when the Torah is unveiled for the first time.
Moshe prepares to face death, and as his farewell to the Jews, the Torah he had been writing is fully revealed. As Devarim is all but complete, Moshe's legacy is complete. While other leaders, princes and prophets, will lead the Jews into Israel, and then into exile, and then back to Israel, Moshe continues to lead the Jews throughout history.
We may not always know what our mission is and what our legacy may be. Sometimes what we think our mission is, turns out not to be our actual mission. And our legacy may turn out to be something else entirely.
Man does his best to define his own mission and legacy, but his perspective is limited. Even the greatest man can pour all his energy and effort into a mission, only for G-d to reveal what his true mission was.
On the brink of death and disappointment, Moshe pours out his heart to his people. And believing that he has failed at his greatest task, he brings it into being. The Torah that is unrolled on the final day of his life, completed by his final effort, his summoning of all his energies to inspire his people, is his legacy.
And on the final day of his life, Moshe realizes that he had not failed at his life's task, he has succeeded at something far greater.