Senator Robert Menendez of New Jersey and his Republican challenger, Bob Hugin, squared off in a debate Wednesday night that simmered with an undercurrent of contempt, but rarely erupted into the mudslinging that has defined the race as the candidates repeatedly focused their disagreements on President Trump’s record.

The only scheduled debate between the men took place as the contest for Mr. Menendez’s seat has become unexpectedly close. Mr. Menendez is seeking re-election in a deeply blue state where Mr. Trump is immensely unpopular during a year when Democratic energy is surging.

But dogged by a federal corruption trial last year that ended in a hung jury, Mr. Menendez has maintained slim leads in most polls and has come under a wave of negative attacks from Mr. Hugin. A poll from Rutgers University released on Wednesday found Mr. Menendez leading by 5 points.

Throughout the hourlong debate in Newark, which was hosted by NJTV, the candidates debated the federal tax law, immigration, race relations and corruption.