Daniel Koh will be the Democratic nominee to replace U.S. Rep. Seth Moulton in Congress. The Andover resident and former White House special assistant bested a herd of party rivals during Tuesday’s primary, according to The Associated Press.

Moulton, of Salem, passed on a re-election bid in order to challenge incumbent U.S. Sen. Ed Markey for a seat in the upper chamber. The Associated Press called the race for Markey earlier in the evening.

Moulton’s departure created something of a political vacuum on the North Shore, and the race drew a number of challengers. Among them were state Rep. Tram Nguyen, Lynnfield businessman John Beccia, Middleton software engineer Beth Andres-Beck, and Topsfield Town Moderator Jamie Belsito. In recent days, Mariah Lancaster had dropped from the race, endorsing Nguyen.

A former White House special assistant, Koh served as chief of staff to Marty Walsh, both when Walsh was Boston mayor and U.S. labor secretary. The 41-year-old previously lost a close race for Congress, though in a different district: In 2018, Lowell-born Lori Trahan eked out a recount victory over Koh in the 3rd District. When the district lines shifted following the 2020 census, the Andover Democrat became a contender in the 6th.

Koh and Beccia in particular spent heavily on the race, carpeting television and YouTube with ads. Nguyen, meanwhile, grabbed significant endorsements from Reps. Ayanna Pressley and Lori Trahan, along with backing by progressive political groups.

Up next is a general election fight against Essex’s Micah Jones, who ran unopposed in Tuesday’s Republican primary.

Tuesday’s primaries guaranteed a power shift on the North Shore. Since 1997, the 6th District has been held by a Salem politician. In 2014, Moulton mounted a successful primary challenge against sitting Congressman John Tierney, who himself was first elected in 1997 but spent years fighting ethics charges related to his wife’s and brother-in-law’s finances. Those charges were dismissed in 2013, but left him politically vulnerable.

Moulton’s willingness to challenge members of his own party became a hallmark of his career, though it never paid the same dividends as it did in 2014. Just four years later, he tried and failed to wrest the House Speaker’s role from the powerful California U.S. Rep. Nancy Pelosi. Two years after that, he made a late, brief run for president but wasn’t able to drum up much interest in his bid.