The United States and Mexico have agreed to restrict nonessential travel across their border to contain the spread of the coronavirus.