The U.S. and Mexico agreed Wednesday to end a ban of nearly two decades on Mexican trucks entering the U.S.

The end of the dispute between the U.S. and its third-largest trading partner came about 2½ years after President Barack Obama killed a Bush administration program to ease the ban. In response, Mexico levied tariffs applied to about $2.4 billion of U.S. goods a year.

The...