Johnston was enthusiastic about the outbreak of the Mexican–American War. He served on the staff of Lt. Gen. Winfield Scott in the Siege of Veracruz, having been chosen by Scott to be the officer carrying the demand for surrender beforehand to the provincial governor. He was in the vanguard of the movement inland under Brig. Gen. David E. Twiggs and was severely wounded by grapeshot performing reconnaissance prior to the Battle of Cerro Gordo. He was appointed a brevet lieutenant colonel for his actions at Cerro Gordo. After recovering in a field hospital, he rejoined the army at Puebla. During the advance toward Mexico City, he was second in command of the "U.S. Regiment of Voltigeurs", a unit composed of light infantry or skirmishers. He distinguished himself at Contreras and Churubusco, was wounded again at Chapultepec, and received two brevet promotions for the latter two engagements, ending the war as a brevet colonel of volunteers. (After the end of hostilities, he reverted to his peacetime rank of captain in the topographical engineers.) Winfield Scott remarked humorously that "Johnston is a great soldier, but he had an unfortunate knack of getting himself shot in nearly every engagement." Johnston's greatest anguish during the war was the death of his nephew, Preston Johnston. When Robert E. Lee informed Johnston that Preston had been killed by a Mexican artillery shell at Contreras, both officers wept, and Johnston grieved for the remainder of his life.