Mexico gained its independence from Spain when Miguel Hidalgo called for a war against the Spaniards; Mexico won the war in 1821. Before the war was over and Mexico gained its independence, the Spanish army murdered Hidalgo.
Spain was an oppressive country over Mexico, and the European country did not let the Mexican people live independently from the laws that governed Spain. The Spanish king pushed for the Mexican people to live in a lower social class, and the Spanish army that ran the city was prejudice against the people of Mexico. The Mexican people grew tired of the oppression, the political offices, the monopolies and the modernization set by Spain, and enforced by the Spanish army.
In 1821, Miguel Hidalgo y Costilla ordered the arrest of all of the Spanish people that lived in the city of Dolores. The Catholic priest had the Spaniards arrested, and he rung his church bell to call people to come to mass. The townspeople gathered around the church where the bell had rung and the priest captured their attention. Hidalgo made it clear that Mexico was going to become independent, and that he was calling for a war against the Spanish.