But in the end, some candidates who rejected Mr. Trump prevailed, others who abandoned him lost and those who tried to avoid the question of his candidacy did fine. Mr. Portman, who started off as a provisional underdog, began an early attack on his opponent, Ted Strickland, the former Ohio governor, over job losses during Mr. Strickland’s tenure. His no-stone-unturned campaign — which even included radio ads in Ukrainian — and a big volunteer network helped him compensate for a less robust turnout operation from the top of the ticket.

The Republican Party’s task appeared to get infinitely more difficult when its voters chose Mr. Trump to head the ticket. Suddenly, the divisiveness was coming not from challengers to the incumbents but from the man running for president who railed against Washington politicians, including many of those seeking re-election.

Most Senate candidates initially remained mum about Mr. Trump’s candidacy, but they were forced, often awkwardly, to react to his many contentious statements.

Mr. McCain and Ms. Ayotte eventually broke with their party’s nominee, saying they could not support his quest for the White House. But Mr. McCain did so not after Mr. Trump insulted him personally or after Mr. Trump offended a Gold Star family, but only when Mr. McCain had obtained a comfortable lead. Ms. Ayotte rejected Mr. Trump after various tortured moments, which cost her support. Mr. Portman stuck to his position of supporting Mr. Trump while largely distancing himself from his remarks.

In Nevada, Mr. Heck, seeking the seat vacated by Mr. Reid, the Democratic leader, renounced Mr. Trump, only to incur a fierce backlash from Trump supporters. Ms. Cortez Masto, who had Mr. Reid’s strong backing, will become the nation’s first Latina senator.

Some themes of the election transcended partisanship. Mr. Blunt, Republican of Missouri, and Mr. Bayh were hit repeatedly for their ties to lobbyists. Mr. Bayh, who began his race with a double-digit lead in polls over Mr. Young, was swamped by negative ads paid for by outside political groups that painted him as out of touch with his state and too in touch with Washington’s insider culture.