In 1821, the Viceroyalty of New Spain was independent and looking for a government, Liberals wanted a Republic and Conservatives wanted a European King, they had neither. They had a Ursuper General called Agustín Ituribe, but he was overthrown little time after taking the throne and a Republic was declared. (First PoD: Central America remained in the Union)
From 1823-1846 Mexico was ruled by a Centralist Republic, controled directly and indirectly by Santa Ana, a powerful caudillo that was a disaster. Under his thumb, Texas, Rio Grande, and Yucatán tried Independence and Texas managed to win against the Federal forces. To avoid a full collapse he gave many concessions to the Central American states, giving considerable autonomy and a special status in the Republic, with their own Parliament.
In 1846 the USA annexed Texas and demanded about Half the Mexican territory, (PoD) but instead of going to fight with a hot head, Santa Ana negotiated a better deal, keeping half of California and the West of the Rio Grande river. President Polk reluctantly accepted due to pressure from the Whigs (PoD: Whigs and moderate Democrats manage to Control Polk's Expansionism.) and the Treaty of Guadaloupe-Hidalgo.
That was his greatest mistake, Britain, France, and Spain invaded Mexico. He negotiated with the British and Spanish to retreat in return of a great sum of money. But money wasn't enough for the French Emperor Napoleon III, he wanted to create a Catholic Empire in Mexico. The French forces took Veracruz in 1862 and later that year, (PoD) the Mexicans were defeated in the battle of Puebla and Mexico City was taken soon after.
The Mexican Conservatives allied with the French Monarchist Ideas and were now looking for a Emperor for Mexico.