in 1810 the mexican priest miguel hidalgo started the mexican war of independence. in 1821 the spanish finally retreated and mexico became independent. the first leader of independent mexico was agustin de iturbide. he set up the first mexican empire and became emperor. but the mexicans were not happy with him, and in 1823 the country became a republic.