The town was founded in 1617 by the Spanish Jesuit missionaries Andrés Pérez de Ribas and Tomás Basilio, although the Spanish inhabitants were eventually forced to leave by the Yaqui native population of the area. In 1835 the town was reestablished, this time in an independent Mexico; the town was a dependency of the municipio of Buenavista. In 1867, the governor of Sonora (Pesqueira) organized two successful military expeditions to control the Yaquis in Cócorit, and in neighboring Guaymas. In 1875, Cajemé, a prominent Yaqui leader, attacked Cócorit, setting the town on fire. Under the protection of the Mexican army, Cócorit was repopulated in 1885 with inhabitants from the neighboring towns of El Quiriego and Baroyeca. In 1886, the Yaquis continued to strengthen their positions, but the state and federal governments confiscated more than 20,000 head of livestock that belonged to the Yaquis, weakening their position. In 1887 Cajemé was captured. After an interview with Ramón Corral, Cajemé was taken in the custody of a Mexican army detachment led by Lieutenant Clemente Patiño to El Médano on the steamboat "Demócrata." He paraded through some of the Yaqui towns, and was then shot by the detachment on the pretense that he was trying to escape.