The conflict between the United States and Mexico in 1846–48 had its roots in the annexation of Texas and the westward thrust of American settlers. On assuming the American presidency in 1845, James K. Polk attempted to secure Mexican agreement to setting the boundary at the Rio Grande and to the sale of northern California. What he failed to realize was that even his carefully orchestrated policy of graduated pressure would not work because no Mexican politician could agree to the alienation of any territory, including Texas.

Frustrated by the Mexican refusal to negotiate, Polk, on January 13, 1846, directed Gen. Zachary Taylor's army at Corpus Christi to advance to the Rio Grande. The Mexican government viewed that as an act of war. On April 25 the Mexican troops at Matamoros crossed the river and ambushed an American patrol. Polk seized upon the incident to secure a declaration of war on May 13 on the basis of the shedding of "American blood upon American soil." Meanwhile, on May 8 and 9, Taylor's 2,200-man army defeated 3,700 Mexicans under Gen. Mariano Arista in the Battles of Palo Alto and Resaca de la Palma Initial American strategy called for a blockade of the Mexican coast and the occupation of the northern Mexican states in the unrealistic hope that these measures would lead to an acceptable territorial settlement. Taylor, reinforced by a large body of volunteers including regiments of Texans, seized Monterrey in September and declared an armistice with General Arista. Col. John Coffee Hays's Texas Mounted Rifles played a significant role in storming the city's defenses. Polk repudiated the armistice, so Taylor thrust south to Saltillo and east to Victoria. A second force under Gen. John E. Wool marched from San Antonio to threaten Chihuahua but ultimately joined Taylor. Gen. Stephen W. Kearny led another column from Fort Leavenworth to seize New Mexico. During July, while Taylor's forces gathered, the navy's Pacific squadron under Commodore John D. Sloat occupied Monterey and San Francisco, California. They linked up with the American settlers there who had established their own government at the urging of the explorer John C. Frémont. Although an incursion into southern California in August failed, the area was secured by a joint army-navy expedition under Kearny and Commodore Robert F. Stockton in January 1847.

Neither American success on the battlefield nor the restoration to power of the deposed strongman Antonio López de Santa Anna brought the expected negotiations. The administration prepared a new army under Gen. Winfield Scott to march from the coast to Mexico City. Santa Anna, aware of the American plans, attempted to defeat Taylor's troops in the north before returning to face Scott's force. The Mexican commander's plan failed when Taylor's largely untested 4,600-man army won a closely contested battle against 15,000 Mexicans at Buena Vista on February 22–23, 1847. The astute reconnaissance work of Maj. Benjamin McCulloch's spy company contributed significantly to the American victory.

A naval squadron under Commodore David Conner put Scott's 10,000-man army ashore near Veracruz on March 9, 1847. It was America's first large-scale amphibious assault. After securing the port as a base, Scott led his army inland. At Cerro Gordo on April 17–18 the Americans destroyed Santa Anna's hastily gathered eastern force of nearly 17,000 men. Scott's advance ground to a halt at Puebla in May, when the volunteers who composed over half his force insisted on returning to civilian life. The American army remained at Puebla, cut off from its base at Veracruz, until reinforcements, especially Texas Rangers under Hays, reopened communications in August.

After initiating a notably successful campaign, Scott set out for Mexico City. In the battles of Contreras and Churubusco on August 19–20, his 8,500 men drove possibly three times their number of Mexican defenders into the Mexican capital. When Santa Anna did not sue for peace as expected, Scott resumed the assault on the city with an attack on its outworks at Molino del Rey on September 8. In the final assault on September 13–14, Scott's force seized the heights of Chapultepec and breached the inner defenses. Santa Anna abandoned the city but salvaged enough of his army to attack Puebla unsuccessfully later in the month. The Mexicans could not prevent American occupation at will of other cities in central and eastern Mexico. Along the Pacific coast the navy, now commanded by Commodore W. Branford Shubrick, also seized the chief port, Mazatlán, neutralized Guaymas, and eliminated Mexican authority in Baja California.

Since no Mexican government functioned after the fall of Mexico City, Scott and the State Department's agent, Nicholas P. Trist, had to wait until February 1848 before a government could be formed that would agree to peace. Then, in the Treaty of Guadalupe Hidalgo, the United States gained California, Arizona, New Mexico, and the Rio Grande boundary for Texas, as well as portions of Utah, Nevada, and Colorado.