When the Aragonese conquered Cagliari, Sardinia from the Pisans in 1324, they established their headquarters on top of a hill that overlooked the city. The hill was known to them as Buen Ayre (or "Bonaria" in the local language), as it was free of the foul smell prevalent in the old city (the Castle area), which is adjacent to swampland. During the siege of Cagliari, the Aragonese built a sanctuary to the Virgin Mary on top of the hill. In 1335, King Alfonso the Gentle donated the church to the Mercedarians, who built an abbey that stands to this day. In the years after that, a story circulated, claiming that a statue of the Virgin Mary was retrieved from the sea after it miraculously helped to calm a storm in the Mediterranean Sea. The statue was placed in the abbey. Spanish sailors, especially Andalusians, venerated this image and frequently invoked the "Fair Winds" to aid them in their navigation and prevent shipwrecks. A sanctuary to the Virgin of Buen Ayre would be later erected in Seville.
In the first foundation, Pedro de Mendoza called the city Santa María del Buen Aire ("Our Lady of the Fair Winds"), a name chosen by the chaplain of Mendoza's expedition, a devotee of the Virgin of Buen Ayre. Mendoza’s settlement soon came under attack by indigenous peoples, and was abandoned in 1541.
For many years, the name was attributed to Sancho del Campo, who is said to have exclaimed: How fair are the winds of this land!, as he arrived. But Eduardo Madero, in 1882, after conducting extensive research in Spanish archives would ultimately conclude that the name was closely linked with the devotion of the sailors to Our Lady of Buen Ayre.
A second (and permanent) settlement was established in 1580 by Juan de Garay, who sailed down the Paraná River from Asunción (now the capital of Paraguay). Garay preserved the name chosen by Mendoza, calling the city Ciudad de la Santísima Trinidad y Puerto de Santa María del Buen Aire ("City of the Most Holy Trinity and Port of Saint Mary of the Fair Winds"). The short form "Buenos Aires" became the common usage during the 17th century.
During most of the 19th century, the political status of the city remained a sensitive subject. It was already capital of Buenos Aires Province, and between 1853 and 1860 it was the capital of the seceded State of Buenos Aires. The issue was fought out more than once on the battlefield, until the matter was finally settled in 1880 when the city was federalized and became the seat of government, with its Mayor appointed by the President. The Casa Rosada became the seat of the President.
In addition to the wealth generated by the Buenos Aires Customs and the fertile pampas, railroad development in the second half of the 19th century increased the economic power of Buenos Aires as raw materials flowed into its factories. A leading destination for immigrants from Europe, particularly Italy and Spain, from 1880 to 1930 Buenos Aires became a multicultural city that ranked itself with the major European capitals. The Colón Theater became one of the world's top opera venues, and the city became the regional capital of radio, television, cinema, and theatre. The city's main avenues were built during those years, and the dawn of the 20th century saw the construction of South America's then-tallest buildings and the first underground system. A second construction boom from 1945 to 1980 reshaped downtown and much of the city.
Buenos Aires also attracted migrants from Argentina's provinces and neighboring countries. Shanty towns (villas miseria) started growing around the city's industrial areas during the 1930s, leading to pervasive social problems and social contrasts with the largely upwardly mobile Buenos Aires population. These laborers became the political base of Peronism, which emerged in Buenos Aires during the pivotal demonstration of October 17, 1945, at the Plaza de Mayo. Industrial workers of the Greater Buenos Aires industrial belt have been Peronism's main support base ever since, and Plaza de Mayo became the site for demonstrations and many of the country's political events; on 16 June 1955, however, a splinter faction of the Navy bombed the Plaza de Mayo area, killing 364 civilians (see Bombing of Plaza de Mayo). This was the only time the city was attacked from the air, and the event was followed by a military uprising which deposed President Perón, three months later (see Revolución Libertadora).