Republicans have fared slightly better in Suffolk County. There, the number of Republicans has grown to 332,000, from 314,000 in the same time — a number that seems encouraging only until one sees the Democratic jolt, to 366,000, from 204,000.

“For an old-timer like me, those numbers are almost incomprehensible,” said Lawrence Levy, the executive dean of the National Center for Suburban Studies at Hofstra University, which is on Long Island. “It is not my mother and father’s suburbs, and it never will be.”

The enrollment shift is inextricable from the island’s rapid diversification, Mr. Levy said. In the 2000 census, non-Hispanic whites made up more than 78 percent of Suffolk County; by 2010, that number was less than 72 percent, and in 2017, 68.5.

“Because of demographic shift, more and more suburban districts are not swing districts anymore,” he said.

Mr. King’s district, which includes both Suffolk and Nassau Counties, is still viewed as swing. Democrats have just a 13,000-person edge over Republicans there, and the Cook Political Report, the independent election handicapper, rated it as “Lean Republican,” even after Mr. King’s announcement.

Sign up for On Politics to get the latest election and politics news and insights. Sign up for our politics newsletter

But Mr. King had seen firsthand the effect of Long Island’s shifting political allegiances.

In his first 12 re-election bids, Mr. King trounced opposing Democrats by double-digit percentage margins. Last year, a Democratic unknown, Liuba Grechen Shirley, lost to Mr. King by just six percentage points. The result was even closer in a neighboring district in Suffolk County, where Representative Lee Zeldin defeated Perry Gershon, a Democrat, by only four points.

Mr. King denied that fears of losing re-election motivated his decision. He said he wanted to spend more time with his family.