How did Peru get its freedom?

The Peruvian War of Independence was initiated by the rebellion of the great indigenous leader Tupac Amaru II against the royalists from 1780 to 1781. Peru's freedom was finally attained after about a decade long struggle that lasted from 1811 to July 28, 1821 until José de San Martín proclaimed its independence.