San Diego
Mexican period

In 1821, Mexico won its independence from Spain, and San Diego became part of the Mexican territory of Alta California. In 1822, Mexico began its attempt to extend its authority over the coastal territory of Alta California. The fort on Presidio Hill was gradually abandoned, while the town of San Diego grew up on the level land below Presidio Hill. The Mission was secularized by the Mexican government in 1834, and most of the Mission lands were granted to former soldiers. The 432 residents of the town petitioned the governor to form a pueblo, and Juan María Osuna was elected the first alcalde ("municipal magistrate"), defeating Pío Pico in the vote. Beyond the town, Mexican land grants expanded the number of California ranchos that modestly added to the local economy. (See, List of pre-statehood mayors of San Diego.)

However, San Diego had been losing population throughout the 1830s, due to increasing tension between the settlers and the indigenous Kumeyaay and in 1838 the town lost its pueblo status because its size dropped to an estimated 100 to 150 residents. The ranchos in the San Diego region would face Kumeyaay raids in the late 1830s and the town itself would face raids in the 1840s.

Americans gained an increased awareness of California, and its commercial possibilities, from the writings of two countrymen involved in the often officially forbidden, to foreigners, but economically significant hide and tallow trade, where San Diego was a major port and the only one with an adequate harbor: William Shaler 's "Journal of a Voyage Between China and the North-Western Coast of America, Made in 1804" and Richard Henry Dana 's more substantial and convincing account, of his 1834–36 voyage, the classic Two Years Before the Mast.

In 1846, the United States went to war against Mexico and sent a naval and land expedition to conquer Alta California. At first, they had an easy time of it, capturing the major ports including San Diego, but the Californios in southern Alta California struck back. Following the successful revolt in Los Angeles, the American garrison at San Diego was driven out without firing a shot in early October 1846. Mexican partisans held San Diego for three weeks until October 24, 1846, when the Americans recaptured it. For the next several months the Americans were blockaded inside the pueblo. Skirmishes occurred daily and snipers shot into the town every night. The Californios drove cattle away from the pueblo hoping to starve the Americans and their Californio supporters out. On December 1, the American garrison learned that the dragoons of General Stephen W. Kearney were at Warner's Ranch. Commodore Robert F. Stockton sent a mounted force of fifty under Captain Archibald Gillespie to march north to meet him. Their joint command of 150 men, returning to San Diego, encountered about 93 Californios under Andrés Pico.

In the ensuing Battle of San Pasqual, fought in the San Pasqual Valley which is now part of the city of San Diego, the Americans suffered their worst losses in the campaign. Subsequently, a column led by Lieutenant Gray arrived from San Diego, rescuing Kearny's battered and blockaded command. Stockton and Kearny went on to recover Los Angeles and force the capitulation of Alta California with the " Treaty of Cahuenga " on January 13, 1847. As a result of the Mexican–American War of 1846–48, the territory of Alta California, including San Diego, was ceded to the United States by Mexico, under the terms of the Treaty of Guadalupe Hidalgo in 1848. The Mexican negotiators of that treaty tried to retain San Diego as part of Mexico, but the Americans insisted that San Diego was "for every commercial purpose of nearly equal importance to us with that of San Francisco", and the Mexican–American border was eventually established to be one league south of the southernmost point of San Diego Bay, so as to include the entire bay within the United States.
keywords:existence