Iturbide's army was joined by rebel forces from all over Mexico. When the rebels' victory became certain, the viceroy resigned. On August 24, 1821, representatives of the Spanish crown and Iturbide signed the Treaty of Córdoba, which recognized Mexican independence under the terms of the plan of Iguala.