After topping a 10-way Democratic primary that finally ended about two weeks after election day, Lori Trahan will go up against Republican Rick Green in the November contest to choose a representative for the Merrimack Valley.

Trahan widened her slim primary-night lead over her closest challenger, Dan Koh, after a district-wide recount ended Monday. The final tally gave Trahan 18,580 votes to Koh's 18,435.

A Lowell native who lives in Westford, Trahan worked for former Rep. Marty Meehan, rising to the position of chief of staff before venturing into the private sector. Meehan is now president of the University of Massachusetts.

"It was clear that this district wanted somebody who had working class values going down to Washington and fighting for them," Trahan told reporters at a Monday evening press conference at the UMass Inn and Conference Center in Lowell. "We need to transition our Democratic party to the future and design an optimistic path forward," she added.

A former Huffington Post executive, Koh was chief of staff to Boston Mayor Marty Walsh before launching his congressional bid.

While Green has not served in government, he has been an active player in Republican politics in Massachusetts. A founder of a political nonprofit with secret donors called the Massachusetts Fiscal Alliance, Green lost a bid for the top position in the state Republican party to Kirsten Hughes in 2013.

Whoever wins the Nov. 6 general election will succeed Rep. Niki Tsongas, who first won office in a 2007 special election after Meehan left Capitol Hill to lead UMass Lowell.

Across the country, polls and the dynamics of an unpopular Republican president portent a wave election that could sweep Democrats into control of the U.S. House, but the Bay State has at times been sheltered from national political trends. The Massachusetts Democratic Party is not taking the race "for granted," according to a party official who said the Merrimack Valley race and another in southeastern Massachusetts should be the two most competitive congressional contests in the state.

The Massachusetts Republican Party claims it has eight field offices in the district, and the National Republican Congressional Committee has listed Green as "on the radar" in its "Young Guns" program to identify candidates who show promise around the country. Peter Tedeschi, a Republican who is challenging Rep. Bill Keating in the 9th district, is listed as a "contender" under the NRCC's metrics.

Gov. Charlie Baker, who is the top Republican elected official in Massachusetts and running for re-election, could fill the sails of candidates like Green and Tedeschi, who are hoping for an against-the-grain Republican victory. The last Republican U.S. House member from Massachusetts was Peter Torkildsen, who represented the North Shore until Democrat John Tierney defeated him in 1998.

In his successful gubernatorial election in 2014, Baker did better in Tsongas's district than in the state as a whole. Statewide, Baker edged Coakley by about 2 percentage points. In the Merrimack Valley congressional district, Baker brought in 10 percent more votes than Coakley. Two years later, on his way to becoming president, Republican Donald Trump didn't crack 40 percent in the district, which includes bucolic towns north of Worcester along with old manufacturing cities along the Merrimack River. Baker remains popular among the Democratic primary electorate.

While other Republican candidates around the country have clung to their party's new standard-bearer, Green has tried to steer the conversation away from Trump toward bread and butter issues like transportation infrastructure.

Green got the jump onto television with a six-figure ad buy of a 30-second spot showing him diving into the Merrimack River and swimming across to prove a point about traffic congestion over a bridge in Lowell. Trahan made clear Monday night she would seek to tie Green to the unpopular president, a tactic that Democrats have used in other races as well.

"We have a well-financed Republican opponent who looks forward to being another voice, another vote, for this president and his divisive policies," said Trahan, who said she supports Democrats up and down the ticket.

Trahan has not yet aired an ad on television, according to her campaign, but it is clear she has seen Green's first offering. Trahan said, "I know that he jumped in a river in our hometown and he swam across it, but we have been very busy winning this election and we are excited to turn our focus to combating Rick's campaign."

"As we finally turn to November, I look forward to discussing the issues that matter most to the residents of this district," Green said in a statement Monday. "For the last year, I’ve seen firsthand the infrastructure issues our district faces. I have heard the heart breaking stories of those suffering from opiate addiction, and I've spoken to families who are tired of Washington squabbling at the expense of their communities."

Green has already had an impact on Massachusetts politics. The group he founded, Mass Fiscal, has dogged Democrats with its own spin on their stances and votes, and the nonprofit sent out more than 1 million mailers featuring its legislative scorecard this summer. The group has historically avoided actively electioneering in the run-up to voting day because of the financial disclosures required, but it has yet to be determined whether Mass Fiscal might play a role in the Merrimack Valley congressional race, according to spokesman Paul Craney.

Green has also been involved in a legal battle seeking to change how campaigns are funded. His company, the Pepperell-based autoparts supplier 1A Auto, sued the Office of Campaign and Political Finance, attempting to legalize corporate funding of candidates or eliminate the provision that allows unions and certain nonprofits to give up to $15,000 to one candidate per year. The Supreme Judicial Court ruled against 1A earlier in September, upholding the ban on corporate political donations.

"It's time for a new breed of leaders, leaders who will stand up for working class families, for seniors, and for women, and root out the corruptive influence of corporate money and special interests," Trahan said on Monday.

Without any Republican primary opponents, Green has been able to run a general election campaign from the get-go. The electoral drama and excitement has been concentrated on the Democratic side as 10 candidates with diverse backgrounds fought it out in debates and on doorsteps.

From that crowded field, Trahan emerged the tentative victor by 52 votes in the Sept. 4 primary, and soon after Koh filed for a recount.

Last week, gas fires rocked the Lawrence area, killing one teenager and causing masses of people to evacuate. Because of the major emergency, the recount location for Lawrence was moved. Trahan said the recount had been "orderly and efficient."

The recount results rolled out over the course of five days, and Trahan's lead grew to 145 out of 88,823 ballots cast by the time the counting ended Monday.

"There's no use in getting upset about the close margin — we can't afford to," Koh wrote in an email to supporters Monday afternoon. "It's time for us to unite behind Lori Trahan to be sure this seat stays Democratic."

Trahan said the women candidates took a majority of the vote in the primary. She said it was a "remarkable" field of Democrats, and she always knew it would be a close race.