In 1821, New Spain gained its independence and became the short-lived Mexican Empire, followed by the Mexican Republic in 1824. Thus Mexico was the new owner of the lands to the south and west of the U.S. Territories. Texas, a province within Mexico, declared its independence from Mexico in 1836 following the Texas Revolution. The Republic of Texas existed as a separate country from 1836 to 1845.