In the First District, which includes the Hamptons and less affluent Long Island towns, Lee Zeldin a well-financed and baby-faced Iraq war veteran, became the Republicans’ lone Jewish representative by beating the Democratic incumbent, Representative Tim Bishop, in a rematch of their 2008 race. The contest was dominated by anti-Obama animus and anger over illegal immigration, as many of the migrant children who crossed the border from Central America ended up on Long Island.

The upstate 24th District was another closely fought race, but late appearances by Vice President Joseph R. Biden Jr. and former President Bill Clinton could not save the seat of Representative Dan Maffei, a Democrat from Syracuse, who lost to John Katko, a former federal prosecutor and political novice.

In District 19, which rolls from the Catskills to apple orchards bordering Vermont, Representative Chris Gibson easily defeated his Democratic challenger, Sean Eldridge, the husband of Chris Hughes, a Facebook co-founder who owns The New Republic. Mr. Gibson characterized Mr. Eldridge as a moneyed carpetbagger who went house — and congressional-seat — hunting.

In the 18th District, Representative Sean Patrick Maloney, a former Clinton administration official and the state’s first openly gay congressman, led by about one percentage point over his opponent, Nan Hayworth, from whom Mr. Maloney had taken the seat in 2012. She had emphasized the decision of Mr. Maloney, who sits on the House Transportation and Infrastructure Committee’s aviation subcommittee, to allow the apparently illegal use of an aerial drone to film his wedding party, which included Representative Nancy Pelosi of California, the House Democratic leader. “That thing is going to kill somebody,” Huma Abedin, an aide to Hillary Rodham Clinton, said at the party.

Outside of New York, Senator Cory A. Booker of New Jersey cruised to re-election, but other Democrats endured more tension. In that state’s Fifth Congressional District, the Republican incumbent Scott Garrett swept aside a young Democrat, Roy Cho, while in the Third District, the Republican Tom MacArthur defeated the Democrat Aimee Belgard to replace retiring Representative Jon Runyan, a Republican.