On September 15, 1821, the general captainate of Guatemala , which included the territory of the present-day states of Guatemala , El Salvador , Honduras , Nicaragua and Costa Rica and was under the viceroyalty of New Spain ( Mexico ), declared itself independent. As a result, the then acting Captain General Gaínza de facto became the first head of government of an independent Central America. Already on January 5, 1822, at Gaínza's instigation, Central America joined the emerging Mexican Empire and lost its independence again. After the overthrow of Emperor Agustín I , Central America declared itself again independent on July 1, 1823, with the governor Filísola appointed by Agustín I trying to establish himself as head of government, which however failed. After various government juntas, Manuel José Arce was elected the first president of the "United Provinces of Central America" at the end of 1824 . This confederation existed until 1840. In 1844, 1852, 1898 and 1921/22 there were attempts to revive it, but were unsuccessful.