What is now California was first settled by various Native Californian tribes before being explored by a number of Europeans during the 16th and 17th centuries. The Spanish Empire then claimed and colonized it. In 1804, it was included in Alta California province within the Viceroyalty of New Spain. The area became a part of Mexico in 1821, following its successful war for independence, but was ceded to the United States in 1848 after the Mexican–American War. The western portion of Alta California was then organized and admitted as the 31st state on September 9, 1850, following the Compromise of 1850. The California Gold Rush started in 1848 and led to dramatic social and demographic changes, with large-scale immigration from other parts of the United States and abroad and an accompanying economic boom.