After the outbreak of the Mexican War, American settlers in California, led by Captain John C. Fremont (1813-90), expelled Mexican authorities and established an independent nation called the Bear Flag Republic at Sonoma on June 14, 1846. In July, an American squadron under Commodore John D. Sloat (1781-1867) captured California's capital, Monterey, hoisted the US flag, and proclaimed California American territory. When General Stephen W. Kearny (1994-1848) arrived there in early 1847, he found California already in US control under Fremont and Commodore Robert Stockton (1795-1866), Sloat's replacement. Stockton and Kearny vied for command, and Fremont backed Stockton. But the US government sustained Kearny, and Fremont was court-martialled for insubordination. California was formally ceded by Mexico in 1848.