Mr. King has agreed to debate Ms. Grechen Shirley on Sept. 8.
Aware of the district’s political shift, Mr. King emphasized in an interview the times he had distanced himself from — and even denounced — Mr. Trump. He cited his criticism of the president’s recent meeting with President Vladimir V. Putin of Russia in Helsinki and Mr. Trump’s comments after the violent rally by white nationalists in Charlottesville, Va., a year ago. (Mr. King was uncontested in the Republican primary.)
Mr. King also voted against Mr. Trump’s signature legislative achievement, the Tax Cut and Jobs Act of 2017. While he supported the cuts themselves, he said he objected to the law’s elimination of the full deduction for state and local taxes, a change that disproportionally impacted high-tax — and largely blue — states like New York and California.
Mr. King also promoted his ability to work with Democrats. He was ranked No. 10 of the 435 members of the House of Representatives in last year’s bipartisan index put out by the Lugar Center and the McCourt School of Public Policy at Georgetown University. In two previous years, he was ranked No. 1.
Ms. Grechen Shirley dismissed this as bipartisan boasting, saying in an interview that on a number of hot-button issues, like the environment and abortion, he leaned to the right.
As for her chances against a Republican Party stalwart, Ms. Grechen Shirley, who won the Democratic primary with 58 percent of the vote, sounded confident. She has won endorsements from Senator Elizabeth Warren and Governor Cuomo, who recently campaigned with her.
“This is a winnable district,” she said. “Nobody has campaigned against King like this before. We have knocked on 50,000 doors and made more than 80,000 phone calls. We’ve built a very broad coalition.”
At a recent meet-and-greet house party, Ms. Grechen Shirley mingled with three dozen voters, along with a volunteer, Cathy Lyons, who said she had voted for Mr. King in every one of his elections. After President Trump was elected, however, she joined a new local progressive group.