Mexico controlled the territory until 1836 when Texas won its independence, becoming an independent Republic. In 1845 it joined the United States as the 28th state. The state's annexation set off a chain of events that caused the Mexican–American War in 1846.