Hanuman was all grown now and soon it was time for him to enter the world, away from the one where Lord Surya had overlooked him. He thanked Lord Surya for all the knowledge and prayed to him. Lord Surya said that soon he would come upon a great being who would change his life forever. With this, Lord Surya departed. Hanuman then went and joined the kingdom of Vali and Sugriva.
Once upon a time, Vali and Sugriva went hunting for a demon. There, Vali told Sugriva to wait outside a cave, where he would go inside. Sugriva obeyed and stayed outside. After some time, Sugriva heard fierce and scary sounds arising from inside the cave and presuming Vali to be dead, he left his spot and returned to the kingdom. Upon his return, as Vali was considered dead, Sugriva was crowned as the new king. After a few days, Vali came back and got furious at seeing Sugriva as the king. How much ever Sugriva tried to explain to him, Vali refused to understand thinking that it was a conspiracy. Vali then fought and exiled Sugriva and also took his wife, Ruma from him.
During the exile, Sugriva and Hanuman came across Lord Rama and Lakshmana. They then struck a deal where Lord Rama would help Sugriva get back his kingdom and Sugriva would help Lord Rama in his search for Sita. Sugriva came from his exile and challenged Vali, when Lord Rama killed him from behind a tree. Before Vali died, he obtained moksha from Lord Rama and also said that his son Angada would help him in his quest to find Sita. In this journey, Hanuman became a close friend of Lord Rama and would help him in a big way to rescue Sita from Ravana.