The Battle of Veracruz from a painting. The Mexican-American war occurred when the United States annexed Texas in 1845. Mexico did not recognize the United States victory in Texas and the ultimate secession. This resulted in a military conflict between 1846 and 1848 between the United States and Mexico.