When Lord Rama’s time of death was at hand, Lord Hanuman barred Yama from claiming him.
When Lord Rama decided to leave his earthly existence for his journey to Vaikuntha (heavenly abode of Lord Vishnu), he knew that Hanuman would not let him do so as he was a great devotee. So he instructed Hanuman to find his ring which had fallen on the ground and then disappeared in the Patal Loka.
Hanuman went on the task of finding the ring and was met by the King of Spirits. He told him that the falling of the ring signified that the time for the end of Lord Ram’s avatar had come.
Hanuman’s journey to Nag Lok:
Ram knew this too had to be gotten done. He took a ring of his and tossed it through a crack in the ground, as though it had fallen accidentally. Next, he asked Hanuman to secure it and bring it back. Hanuman assumed a nano form and dived into the crack.
Only, the crack was no ordinary crack in the Earth. It led straight to the Nag Lok, the world of serpent king Vasuki. Once he reached there he met Vasuki and asked him about Rama’s ring.
Vasuki pointed to a hill or a pile of rings. Every ring there looked like the one that belonged to Rama. Vasuki philosophically explained that anyone who has taken birth must also leave (die) someday and that these rings were from the innumerable avatars the Lord has taken over time. Hanuman realised that when he returned to Earth, he cannot hope to see his beloved master Rama.
Rama leaves for Heaven:
Upon the Earth’s surface, Rama walked into the Sharayu (Sarayu) river to wrap up his avatar as the (prince who became) king of Ayodhya. Along with him, his surviving brothers Bharat and Shatrughna also followed.
I am sure it left you with an idea of the immense pain that Bajrangbali Hanuman must have realised while accepting that Rama’s journey on Earth was done.