The Treaty of Guadalupe Hidalgo was the agreement that helped end the Mexican-American War. In this agreement, the Mexican government agreed to give up a significant amount of territory to the United States, including Arizona, Nevada, and parts of New Mexico.
Everything west of the Rio Grande River became part of US territory. This is the beginning of the development of New Mexico as a US state. From there, the New Mexico territory started to develop and eventually became an organized territory of the US. After almost 6 decades as an organized state, New Mexico had the population and state constitution necessary to become part of the United States.