José de San Martín played a crucial role in the liberation of Peru from Spanish rule, and he worked alongside Simón Bolívar in the larger struggle for independence in South America. However, his main contribution to Bolívar's efforts in Peru was that he gave Bolívar control of the city of Lima after successfully liberating it from Spanish forces.
San Martín was instrumental in the initial stages of the liberation of Peru, and he proclaimed its independence in 1821. However, he faced challenges in consolidating power and dealing with the complexities of the local political landscape. In 1822, he met with Bolívar in Guayaquil and ultimately decided to withdraw from Peru, allowing Bolívar to take command of the military efforts to further defeat the remaining Spanish forces there. This collaboration and transfer of leadership were pivotal in securing Peru's independence.