In 1845, during the annexation of Texas, President James K. Polk dispatched Taylor to the Rio Grande in anticipation of a battle with Mexico over the disputed Texas–Mexico border. The Mexican–American War broke out in April 1846, and Taylor defeated Mexican troops commanded by General Mariano Arista at the battles of Palo Alto and Resaca de la Palma and drove his troops out of Texas. Taylor then led his troops into Mexico, where they defeated Mexican troops commanded by Pedro de Ampudia at the Battle of Monterrey. Defying orders, Taylor led his troops further south and, despite being severely outnumbered, dealt a crushing blow to Mexican forces under Antonio López de Santa Anna at the Battle of Buena Vista. Taylor's troops were transferred to the command of Major General Winfield Scott, but Taylor retained his popularity.