The San Francisco Bay itself remained undiscovered by Europeans until members of the Portolá expedition, while trekking along the California coast, encountered it in 1769 when the bay blocked their continued journey north. In 1806, a Spanish expedition led by Gabriel Moraga began at the Presidio, traveled south of the bay, and then east to explore the San Joaquin Valley. In 1821, Mexico gained its independence from Spain and the Bay Area became part of the Mexican province of Alta California, a period characterized by ranch life and visiting American trappers. Mexico's control of the territory would be short-lived, however, and in 1846, a party of settlers occupied Sonoma Plaza and proclaimed the independence of the new Republic of California. That same year, the Mexican–American War began, and American captain John Berrien Montgomery sailed the into the bay and seized San Francisco, which was then known as Yerba Buena, and raised the American flag for the first time over Portsmouth Square.