The struggle was long and hard, lasting over a decade. It officially ended on September 27, 1821, when Spain finally recognized Mexico's independence.