The city was first founded by a Spanish gold-seeking expedition led by Pedro de Mendoza on 2nd February 1536, who named it Nuestra Señora Santa María del Buen Aire ("Our Lady St. Mary of the Good Air"). In 1539, attacks by the native people forced the settlers away, and in 1541 the old site was destroyed. In 1580, Juan de Garay from Asuncion, the capital of Paraguay, established a permanent settlement here.
The city remained under the authority of a Spanish viceroy in Peru until 1776. It was the Rio de la Plata viceroyalty capital, including much of present-day Argentina, Uruguay, Paraguay, and Bolivia. The Spanish insisted on some rules that frustrated the traders of the city. The people were not happy with the Spanish rules. After noticing a deep resentment in locals, Charles III of Spain gradually simplified the trade restrictions. Finally, in the late 1700s, he declared Buenos Aires an open port. However, most of the residents were hoping for separation from the Spanish Empire.
During the Rio de la Plata attacks, the British invaded the city twice in 1806 and 1807. But the local militants managed to drive back the forces both times. Eventually, when Spain was busy with the Peninsular War, the town council's armed people expelled the Spanish Viceroy and founded a provisional representative government on 25th May 1810. This day, 25th May, is now celebrated as a national holiday or May Revolution Day all over the country. Later on, the Spanish ruler officially declared Independence from Spain in 1816.
Buenos Aires had remained an important centre for liberal and free-trade ideas in Argentina. However, some of the other provinces were having a Catholic approach to political and social issues. These contrasting views became the reason for some conflicts later. After 25th May Revolution, the forces of the city tried to obtain the approval of other provinces. Many of these missions resulted in violent clashes.
In the 19th century, the city faced two naval blockades, first by the French from 1838 to 1840 and another joint Anglo-French blockade from 1845 to 1848. Eventually, the external powers stopped their demands, and in 1853, the internal conflicts forced Buenos Aires province to separate from Argentina. But after the National political unity, the city became the capital of Argentina in 1862. Further tensions between the city and province resulted in the detachment of the city from the province.
During the second half of the 19th century, the city flourished by all means. The city's economic power increased with the help of wealth generated by the fertile pampas and railroad construction. The city became a multicultural metropolitan and graded itself with the major European capitals. By the 1920s, it became the favoured destination for immigrants from all over Europe, Argentina's provinces and neighbouring countries.
Due to economic crises, some citizens moved to the outskirts of the larger cities, resulting in new villas around the town. In 1935, the population jumped to the 3.5million marks. The city experienced bombing on 16th June 1955, killing about 360 civilians. In the 1970s, it suffered from the fighting between left-wing revolutionary movements (Montoneros, E.R.P., and F.A.R.) and the right-wing paramilitary group Triple A. Jorge Rafael Videla which led to the military coup of 1976. Some development plans took place during the years of dictatorship.
Bomb explosions between 1992 and 1994 destroyed the buildings and several Jewish organisations of the city. In 1996, the city gained autonomous status and held its first mayoral elections. In 2004, the city again underwent one of the greatest non-natural tragedies in Argentine history. A fire at Republica Cromagnon nightclub became the cause for the death of about 200 people.
In the 2007 elections, Mauricio Macri was elected as a mayor and María Vidal as deputy mayor. In the 2015 elections, Macri stepped down, and Horacio Larreta took his place as mayor and Diego Santilli as deputy.