José de San Martín and his forces liberated Peru and proclaimed its independence from Spain on 28 July 1821. ... After securing Chilean independence, with a fleet commanded by the adventurous Lord Cochrane, he invaded Peru and declared independence in Lima in 1821, with himself as dictator.