Human history in California began when indigenous Americans first arrived some 13,000 years ago. Coastal exploration by the Spanish began in the 16th century, with further European settlement along the coast and in the inland valleys following in the 18th century. California was part of New Spain until that kingdom dissolved in 1821, becoming part of Mexico until the Mexican–American War (1846–1848), when it was ceded to the United States under the terms of the 1848 Treaty of Guadalupe Hidalgo. The same year, the California Gold Rush began, triggering intensified U.S. westward expansion. California joined the Union as a free state via the Compromise of 1850. By the end of the 19th century, California was still largely rural and agricultural, with a population of about 1.4 million.