People settled here around AD 200, and the sites show influence from Teotihuacan. The hill now called El Cerrito was a ceremonial centre, later abandoned for reasons nobody knows. By the 1440s the area belonged to the Otomi dominion of Xilotepeque, which paid tribute to the Aztec empire.
The Spanish city dates its founding to 25 July 1531, when Hernán Pérez Bocanegra arrived with the Otomi leader Conín. Chronicles say the Chichimeca were close to winning when a total solar eclipse came. The Spanish gained control only gradually, and one battle did not decide it.
Conín placed the Otomi on and around Sangremal and the Spanish where the historic centre is now. The Spanish side was laid out as a grid, and the Otomi side in their own way. UNESCO notes that the grid still sits beside twisting alleys.
The settlement became a town in 1606, and in 1656 the Crown gave it the title of Very Noble and Loyal City. In the 1700s it picked up two nicknames: Pearl of the Bajío, and the viceroyalty's third city. The Royal Convent of Santa Clara became one of the largest and richest in New Spain. The Colegio de Propagación de la Fe, set up in 1683 at Santa Cruz, trained many of the missionaries who headed for Texas and California. Most of the oldest buildings you see are Baroque.
Querétaro is called a cradle of Mexican independence, mostly thanks to Josefa Ortiz de Domínguez. Her tertulias turned into the Conspiracy of 1810. Officials found out before the plotters could act. She still got a warning to Miguel Hidalgo. She died poor and forgotten, and she later became the first woman on a Mexican coin.
In 1847 the city was declared the capital of Mexico when US forces invaded, and the Treaty of Guadalupe Hidalgo was signed here the next year. In 1867 liberals besieged Emperor Maximilian here, took him prisoner and sentenced him to death on the Cerro de las Campanas. A memorial chapel on that hill was built by his brother. The 1917 Constitution was enacted here, and Mexico still lives under it.
Agriculture dominated outside the city until the 1970s. Industrial growth since the mid-1990s has changed that. The metropolitan area had 1,594,212 people in 2020, and most of its growth comes from migrants arriving from Mexico City, Guanajuato, Michoacán and Veracruz. Tourism has also grown, especially in the city proper.