CAPE GIRARDEAU, Mo. — President Trump on Monday closed out an us-against-them midterm election campaign that was built on dark themes of fear, nationalism and racial animosity in an effort to salvage Republican control of Congress for the remaining two years of his term.

Mr. Trump’s fiery, invective-filled campaigning produced what may be the most polarized midterm contest in modern times as he played to tribal rifts in American society in a way that no president has done since before the civil rights era. The divisions exposed and expanded over the past few weeks seem certain to last well beyond Election Day.

On Tuesday, voters will choose a new House, decide one-third of the seats in the Senate and select new governors for battleground states that will be critical to the 2020 presidential campaign. On the line for the president will be his ability to legislate, build his promised border wall, appoint new judges and ultimately set the stage to run for a second term.