Mexican War of Independence
Although Mexico gained its independence in September 1821, the marking of this historical event did not take hold immediately. The choice of date to celebrate was problematic, because Iturbide, who achieved independence from Spain, was rapidly created Emperor of Mexico. His short-lived reign from 1821–22 ended when he was forced by the military to abdicate. This was a rocky start for the new nation, which made celebrating independence on the anniversary of Iturbide's Army of the Three Guarantees marching into Mexico City in triumph a less than perfect day for those who had opposed him. Celebrations of independence during his reign were marked on September 27. Following his ouster, there were calls to commemorate Mexican independence along the lines that the United States celebrated in grand style its Independence Day on July 4. The creation of a committee of powerful men to mark independence celebrations, the "Junta Patriótica", organized celebrations of both September 16, to commemorate Hidalgo's grito and the start of the independence insurgency, and September 27, to celebrate actual political independence.
History of Mexico City
When rebellion against Spanish rule broke out, interests outside of Mexico City would be represented by Father Miguel Hidalgo y Costilla, José María Morelos and others. While the nobility in Mexico City also did not like the absolute colonial system, their goal was limited representation and autonomy within the Spanish empire. They decided to make their stand in 1820, after the rural insurgency had been going on for several years, choosing Colonel Agustín de Iturbide to push their interests militarily. Iturbide had fought against Morelos between 1813 and 1816. However, between 1816 and 1820, Iturbide was becoming sympathetic to the idea of some degree of independence for Mexico. In 1821, Iturbide was the supreme commander of the royalist forces and had put down all but one of the major rebels, Vicente Guerrero. Iturbide decided to meet with Guerrero, after becoming convinced that independence was the only real course for Mexico. However, Iturbide's idea was a Mexican monarchy with ties to King Ferdinand VII of Spain.
After switching sides, Iturbide chose to pressure the colonial government by repeating Hidalgo's strategy of closing in on the city from the surrounding area. Iturbide was able to succeed where Hidalgo had not because the Spanish-born commanders in the city supported Iturbide's idea of limited autonomy, and many the royalist forces were in the field battling insurgents like Guerrero. Iturbide's Army of the Three Guarantees (Independence, Union, Religion) entered Mexico City on 21 September 1821. On the following 27 September, Mexico was declared independent.
The Mexico City nobles sought to preserve as much of the old as possible, and garnered the support of a substantial section of the royalist army to recreate central power. Their objective was to halt the devolution of power to the regions outside the city and the lower echelons of society. Shortly after his triumphant entrance into the city, Iturbide declared what is now known as the First Mexican Empire, with himself as emperor, from the palace that now bears his name. The coronation of Agustín as emperor and his wife Ana María as empress took place amid much pomp and circumstance on 21 July 1822 at the Cathedral of Mexico City. The Archbishop Fonte presided over the anointment of the Emperor who following Napoleon's example, crowned himself.
Following his coronation, the new empire was politically and financially unstable. Iturbide was accused of taking too much power for himself, and his main rival was Antonio López de Santa Anna. In the spring of 1823, Iturbide offered his abdication, which was accepted by his political opponents and then left the country for Europe. 
Mexico was then declared a republic. The republican constitution of 1824 established Mexico City as the nation's capital. Unrest followed for the next several decades, as different factions fought for control of Mexico.