Afro-Mexicans played an important role in the Mexican War of Independence, most prominently with insurgent leader Vicente Guerrero, who became commander in chief of the insurgency. The initial movement for independence was led by the American-born Spaniard priest Miguel Hidalgo y Costilla in central Mexico. White Mexicans quickly abandoned the movement for independence which had become more of a social revolution, with Indians, mixed-race castas, and other plebeians seeking social equality. The movement for independence remained active on the Gulf Coast and the Pacific Coast, where there were large concentrations of Afro-Mexicans. The royal army and the insurgent forces had reached a stalemate militarily, but the equation changed in 1820. American-born Spaniard and royalist officer Agustin de Iturbide sought an alliance with the insurgents led by Guerrero. Iturbide and the white creoles sought independence, but expected that racial hierarchies would continue in the post-independence period. Guerrero and other Afro-Mexicans demanded that they would be equal citizens and not until Iturbide acceded to that demand did the Afro-Mexican forces sign on to the Plan of Iguala which laid out the terms for the insurgency movement.
When Napoleon Bonaparte invaded the Iberian peninsula, the Spanish Bourbon monarchy was displaced, with Charles IV abdicating the throne and Napoleon's brother Joseph placed on the throne of Spain. For peninsular Spaniards and those in the overseas Spanish Empire in the Americas, the question of legitimacy of the monarchy was a crucial question. In Iberia, the Peninsular War raged between 1807-1814; in Spanish America, a number of regions set up local juntas, ruling in the name of the Spanish king sprang up. In New Spain (Mexico), the outbreak of an insurgency for independence came from elite America-born Spaniards who sought independence. Among them was the priest Miguel Hidalgo y Costilla, formerly the rector the seminary in Michoacan to train priests, now exiled to the small village of Dolores as its parish priest. In September 1810 he issued what is known in Mexican history as the Grito de Dolores, denouncing bad government of the Spaniards, loyalty to the Virgin of Guadalupe and Ferdinand VII (considered the legitimate Spanish monarch. In the region north of Mexico City, known as the Bajío, the movement quickly swelled with poorly armed plebeians, who attacked property owned by whites, peninsular-born or American-born, causing them to abandon the cause of independence in the face of a social revolution. Royalist forces caught Hidalgo, defrocked him, and tried and executed him in 1811. The cause for independence was taken up by his former seminary student, a mixed-race priest José María Morelos y Pavón. Morelos was likewise caught by royalists and executed. The insurgency was continued under the leadership of former muleteer Vicente Guerrero in the southern hot country of Mexico, along with many other Afro-Mexicans, castas, and Indians, the dark-skinned plebeians. 
At the time of the outbreak of the insurgency for independence, there was a large Afro-Mexican population of mainly free blacks and mulattos, as well as mixed-race castas who had some component of Afro-Mexican heritage. Black slavery still existed as an institution, although the numbers of enslaved had declined from the high point in the 1600s, when the Atlantic slave trade had brought enslaved Africans to Spanish America. For the period 1580-1640, Spain and Portugal were ruled by the same monarch and Portuguese slave dealers could freely operate in Spanish American territory. When the Portuguese revolted against Spain in 1640, the numbers of slaves brought from Africa dropped precipitously and the demand for slaves was met by natural reproduction of American-born Africans. Children of enslaved women became slaves themselves, so that marriage to non-slave women meant the off-spring were free. Unions between enslaved men and free black or mulatto women increased the population of the Afro-Mexican community, but there were also many unions between blacks and women of other ethnicities, resulting in a large, free mixed-race population.
Enslaved Afro-Mexicans were prominent in enclosed seventeenth-century work spaces. They toiled in textile workshops (obrajes), since the Spanish crown mandated that Indians not be forced to work there. Obraje owners were forced to invest some 300 pesos per slave to secure their labor force. Most slaves in obrajes were male. There were enslaved women in convents, usually the private property of individual elite white women who had become nuns, but some slaves were the property of the nunnery as an institution. Male religious orders also owned enslaved, mainly male. Enslaved Afro-Mexican men worked in the mining sector. There were Afro-Mexican men, some of who were ex-slaves, who herded cattle, while others were muleteers (arrieros), the occupation of Vicente Guerrero before he joined the insurgency for independence.
The fight for independence originated in the central area of Mexico, but with the failure of the insurgency there and the capture and executions of Hidalgo and other insurgent leaders, the insurgency shifted to the South, where the population was predominantly indigenous and mixed race. On the Pacific coast, which has been called the "Revolutionary Coast" the main locus of Spanish economic activity was the port of Acapulco, terminus of the Manila galleons, which brought Chinese porcelains and silks, as well as Asian slaves (known as Chinos). The port was the midpoint in the settled coast, with the Costa Chica to the southwest and the Costa Grandeto the northwest. The Pacific coastal region underwent a population decline in the sixteenth century after the Spanish conquest of the Aztec empire in 1521, with indigenous populations succumbing to diseases brought by the Europeans. Spanish conquerors who were awarded labor grants found few Indians and the region became a destination of runaway African slaves, many of whom formed unions with indigenous women. Starting around 1600, Spaniards saw in the Pacific coast the opportunity for tropical agriculture and imported slaves for cotton cultivation. Slave flight to nearby mountains and a strong impulse toward manumission of slaves created a strongly Afro-Mexican population, with Indian and Asians added to the mix. The 1793 population census recorded an overwhelming number of pardos, free Afro-Mexicans. The Gulf Coast was tropical as well and conducive for sugar plantations, whose Spanish owners utilized black slave labor, who strongly supported independence. The topography was similar to the Pacific Coast, with mountains rising behind the coastal strip. There were few white residents in the region. In the south, insurgent priest José María Morelos led a growing army of mixed-race men.
A student of Hidalgo at the seminary was José María Morelos, who emerged as a leader of independence following the death of his mentor in 1811. Morelos sat for a portrait in 1812, which depicts him as a very dark skinned man. Some historians have described him as Mestizo (mixed Spanish and Indian ancestry), but others point to archival evidence that Morelos's mother was a "free woman", that is either a Negra or Mulata, and he was under investigation at the outbreak of the insurgency as to whether he was qualified for the priesthood as a Spaniard. Blacks were barred from taking holy orders. Morelos took to wearing a scarf over his "curly" hair, which one scholar says "suggests a lack of acceptance of his African roots." Morelos was a muleteer prior to his studying for the priesthood, a line of work that many mixed race men pursued, including Vicente Guerrero. It is unclear why he became a priest, but he succeeded in seminary was assigned a parish of mixed in the "hot country" of southwest Mexico. Priests in relatively remote parishes often functioned as officials carrying out crown business. Morelos was tasked with carrying out a census of his parishioners, one component of which was determining the racial status of his parishioners; however, he declined to provide the racial information.
Morelos's military campaign was based along the west coast of Mexico and its interior, a region that had a predominantly mixed-race population. Among those who distinguished themselves in his military campaign were Afro-Mexicans Hermenegildo Galeana and Vicente Guerrero. Galeana was killed in battle in 1814, much to the distress of Morelos.
Upon Miguel Hidalgo's death the army declined and the future was not looking very promising. Guerrilla warfare seemed to be the main line of attack. The army was now under the command of Vicente Ramón Guerrero Saldaña, more generally known as Vicente Guerrero. Born to a poor family of mixed-race farmers in 1782 in Tixtla, near Chilpancingo, in the Mexican state now named for him Guerrero (state) to a poor family of farmers, Guerrero came to distinguish himself as a leader due to his oratory skills and ability to speak different languages. Although he had little formal education he possessed other skills that helped him as a military leader, such as having knowledge of the geography of the region, this helped entering to towns where the access to main roads was difficult. Although his four-year command was mostly a holding action and the military was almost always on the brink of collapse, he was considered one of the greatest Mexican war heroes. He is identified as the "consummator of the Mexican independence". When approached by former royalist officer Agustín de Iturbide to join forces against the Spanish, Guerrero did agree to the alliance under the Plan de Iguala and the combined forces, known as the Army of the Three Guarantees was formed. Spanish imperial rule collapsed, and Mexico gained its independence in September 1821.