At first, the fort El Presidio Real de San Francisco was built here. The settlement gained independence from Spain in 1821 and was incorporated into the United States in 1848 after the Mexican-American War.