In 1549, Bogotá was given the status of capital of New Granada, which comprised in a large part of what is now the territory of Colombia. In 1717, the Spanish created the Viceroyalty of New Granada, which included also modern-day Venezuela, Ecuador and Panama, making Bogotá one of the principal administrative centres of the Spanish possessions in the New World, along with Lima and Mexico City.
In 1811, seven of the ten provinces of the Captaincy General of Venezuela declared their independence. The struggle for independence was hindered by constant conflicts and fighting between Federalists and Centralists, giving the Spanish the opportunity to keep control of all New Granada for some more time. However, in 1819 Bolívar led an army from Venezuela over the Andes and captured New Granada after a short campaign. The Congress of Angostura established the Republic of Gran Colombia in 1819, which included all territories previously under the jurisdiction of the Viceroyalty of New Granada. Bolívar was elected its first president. Internal tensions initiated by José Antonio Páez led to the dissolution of Gran Colombia, with Venezuela becoming a sovereign country in 1831, and the Department of Cundinamarca a new country, the Republic of New Granada, later the Republic of Colombia.