A state court formally approved New York’s new congressional map late Friday, ratifying a slate of House districts drawn by a neutral expert that could pave the way for Democratic losses this fall and force some of the party’s most prominent incumbents to face off in primary matches.

The map, approved just before a midnight deadline set by Justice Patrick F. McAllister of State Supreme Court in Steuben County, effectively unwinds an attempted Democratic gerrymander, creates a raft of new swing seats across the state, and scrambles some carefully laid lines that have long determined centers of power in New York City.

Jonathan R. Cervas, the court-appointed mapmaker, made relatively minor adjustments to a draft proposal released earlier this week whose sweeping changes briefly united both Republicans and Democrats in exasperation and turned Democrats against each other.

In Manhattan, the final map would still merge the seats of Representatives Carolyn Maloney and Jerrold Nadler, setting two Democratic committee leaders who have served alongside each other for 30 years onto a collision course with national implications.

Another awkward Democratic primary loomed up the Hudson in Westchester County, where two Black Democratic House members were drawn into a single district. But the worst outcome for Democrats appeared to be averted early Saturday morning when one of the incumbents, Representative Mondaire Jones, said he would not run for re-election in Westchester.

He planned to run instead in a newly reconfigured 10th District in Lower Manhattan and Brooklyn, a race that will also include Bill de Blasio, the former New York City mayor, and Assemblywoman Yuh-Line Niou.

Republicans were already eying pickup opportunities in the suburbs of Long Island and the Hudson Valley that could help them retake control of the House.

And in New York City’s only Republican-held district, Representative Nicole Malliotakis breathed a sigh of relief that Mr. Cervas had reversed one of the boldest moves by the Democratic leaders in the State Legislature, when they inserted liberal Park Slope, Brooklyn, into her Staten Island-based district.

The shift could doom a comeback attempt by Max Rose, a Democrat, who did not immediately say whether he would remain in the race.

Some of the most notable changes between the initial and final district lines came in historically Black communities in Brooklyn, where Mr. Cervas reunited Bedford-Stuyvesant and Crown Heights into single districts. He had faced uproar from Black lawmakers and civil rights groups after his first proposal divided them into separate seats.

Mr. Cervas also revised the map to reunite Manhattan’s Chinatown with Sunset Park in Brooklyn, another heavily Asian American community, in the 10th Congressional District. In each case, he said, the communities had been “inadvertently split” in his first proposal.

Justice McAllister’s order approving the congressional and additional State Senate maps on Friday makes New York one of the final states in the nation to complete its decennial redistricting process.

But both parties were already girding for civil rights or political groups to potentially file new, long-shot lawsuits challenging the maps.

Representative Hakeem Jeffries, a Brooklyn Democrat and top party leader, called the maps a “constitutional travesty” on Saturday, saying that Mr. Cervas’s last-minute changes had still resulted in Black and Latino voting populations shrinking in a handful of districts. Still, he stopped short of saying he or others would file suit.

Justice McAllister used the unusual five-page order to rebut criticisms leveled at Mr. Cervas and the court, as the maps were hastily drafted out of public view. He conceded that the time frame was “less than ideal” but defended the final maps as “almost perfectly neutral” with 15 safe Democratic seats, three safe Republican seats and eight swing seats.

“Unfortunately some people have encouraged the public to believe that now the court gets to create its own gerrymandered maps that favor Republicans,” wrote Justice McAllister, a Republican. “Such could not be further from the truth.”

The final map was a stark disappointment for Democrats, who control every lever of power in New York and had entered this year’s decennial redistricting cycle with every expectation of gaining seats.

They appeared to be successful in February, when the Legislature adopted a congressional map that would have made their candidates favorites in 22 of 26 districts, an improvement from the 19 Democrats currently hold.

But Republicans sued in state court, and Justice McAllister, a judge in the state’s rural Southern Tier, ruled that the districts violated a 2014 state constitutional amendment outlawing partisan gerrymandering and reforming the mapmaking process in New York.

In late April, the New York Court of Appeals, the state’s highest court, upheld the decision and ordered a court-appointed special master to redraw the lines.

Justice McAllister appointed Mr. Cervas, a postdoctoral fellow at Carnegie Mellon with few ties to New York and scant experience drawing state lines, and delayed the congressional and State Senate elections until Aug. 23.

On Friday, Mr. Cervas produced a 26-page report explaining the rationale of his map.

He eliminated one district overall, carving it out of central New York to shrink the state’s congressional delegation to 26. The change was required after New York failed to keep pace with national population growth in the 2020 census.

He made a slew of other changes, responding to a crush of feedback to the initial proposal. For instance, he reoriented his maps for Long Island considerably, creating districts that divided the island north-south rather than east-west, but kept them highly competitive.

Still, Mr. Cervas rejected pleas to revert to a traditional east-west split of Manhattan. Doing so would have allowed Mr. Nadler, 74, and Ms. Maloney, 76, to run in their own districts, avoiding a messy primary conflict, but the special master wrote that he “did not find a compelling community of interest argument for changing the configuration.”

On Saturday, Mr. Nadler and Ms. Maloney both said they would run in the newly created 12th Congressional District.

“Too often qualified and accomplished women have been told to stand aside for the sake of men’s egos,” Ms. Maloney said. “But I have a lifetime of experience standing up to powerful men.”

Mr. Nadler said, “the new district belongs to no individual candidate, but instead to the voters who call it home.”

Just to the south, a growing number of candidates have declared their interest in running for the 10th District, which will encompass all of Lower Manhattan and a large swaths of Brooklyn.

Mr. de Blasio declared his candidacy on Friday before the lines were finalized. Hours later, Mr. Jones surprised Democrats by announcing that he would follow suit. He has minimal ties to the district, but already has nearly $3 million in his campaign account.

“This is the birthplace of the L.G.B.T.Q.+ rights movement,” said Mr. Jones, who is gay. “Since long before the Stonewall Uprising, queer people of color have sought refuge within its borders.”

Ms. Niou, a Taiwanese-American progressive who represents Chinatown, declared her candidacy Saturday afternoon.

Representative Nydia Velázquez, the first Puerto Rican woman to serve in the House, lives within the new district lines, but reiterated on Saturday that she would run in the nearby Seventh District.

Mr. Jones’s decision will help avert another tense intraparty showdown in the Lower Hudson Valley.

The potential conflict emerged earlier this week, when Representative Sean Patrick Maloney, the Democratic Congressional Campaign Committee chairman, announced that he would seek to represent territory currently included in Mr. Jones’s seat. The decision would have forced Mr. Jones to compete in a primary with either Mr. Maloney in the 17th District or a fellow progressive congressman, Jamaal Bowman, in the neighboring 16th District.

Two upstate Republicans also averted a potential primary conflict. Representative Claudia Tenney said she would run for the new 24th District stretching from the outskirts of Buffalo to the eastern shore of Lake Ontario, and Representative Chris Jacobs said he would run for the 23rd District covering the Southern Tier.