Republicans eyed a recount and a lawsuit over perceived irregularities in a closely watched U.S. House race in Pennsylvania where Democrat Conor Lamb clung to a slender lead in the longtime GOP stronghold friendly to President Donald Trump.

With the last batch of absentee ballots counted, Lamb, a 33-year-old former prosecutor and first-time candidate, saw his edge over Republican Rick Saccone shrink slightly, to 627 votes out of more than 224,000 cast, according to unofficial results.

The four counties in the Pittsburgh-area district reported they had about 375 uncounted provisional, military and overseas ballots. They have seven days to count the provisional ballots, and the deadline to receive military and overseas ballots is next Tuesday.

With the margin so close, supporters of either candidate can ask for a recount.

The GOP is considering lodging a recount request, and county officials reported receiving a letter from a law firm requesting that they preserve their records, something the counties say they do anyway under state law.

Separately, Republicans mulled legal action, according to a person familiar with the deliberations. This person spoke on condition of anonymity to discuss internal planning.

Complaints could include that party lawyers were prevented from observing the counting of some absentee ballots, voting machines erroneously recorded votes from Lamb, and voters were confused by some information from the state elections website.

Officials in Allegheny County, the most populous and Democratic-leaning county in the district, pushed back on Republican claims Wednesday, saying the lawyers had lacked written authorization from the GOP and they had received no reports Tuesday of malfunctioning voting machines.

The Associated Press has not called the race, which is seen nationally as indicator of Democratic enthusiasm and GOP vulnerability heading into the November elections that will determine whether Republicans retain their control of Congress.

Lamb has declared victory. Saccone, a 60-year-old Air Force veteran turned state lawmaker and college instructor, hasn't conceded. Both men stayed out of sight Wednesday, and Saccone's campaign said that Saccone had no plans to concede before vote counting was finished.

The counties, under state law, perform an audit of the results on the electronic voting machines that typically involves comparing the overall tally on a hard drive, a flash drive and a paper tape that separately record each vote. Deviations are a rarity, county officials say.

Absentee ballots are open to inspection to determine whether the person is eligible to vote or whether the voter's intent was clear, and that is more likely where a review might alter a final count, said Douglas Hill, executive director of the County Commissioners Association of Pennsylvania.

But a difference is "never large numbers, it's always around the margins," Hill said.

Regardless of the outcome, Lamb's showing seemed certain to stoke anxiety among Republicans nationwide and renew enthusiasm among Democrats.

Trump won the district by about 20 percentage points in 2016, and the seat has been in Republican hands for the past 15 years. It was open now only because Republican Rep. Tim Murphy, who espoused strong anti-abortion views, resigned last fall amid revelations that he had asked a woman with whom he was having an extramarital affair to get an abortion.

Democrats must flip 24 GOP-held seats this fall to seize control of the House, and months ago few had counted on this district to be in play.

Lamb asserted his independence from national Democratic leaders and played down his opposition to Trump. But he also fully embraced organized labor in a district with influential labor unions and a long history of steel-making and coal-mining, hammering Republican tax cuts as a giveaway to the rich and promising to defend Social Security, Medicare and pensions.

Trump and his allies, meanwhile, invested tremendous time and resources in the seat, mindful the contest could be used to measure Trump's lasting appeal among white, working-class voters and Democrats' anti-Trump fervor.

Outside groups aligned with Republicans poured more than $10 million into the contest, about seven times the outside money that helped Lamb.

Saccone had cast himself as the president's "wingman." But where Murphy had long allied himself with unions, Saccone's conservative voting record alienated them.

A White House spokesman on Wednesday warned against reading too much into the razor-thin outcome, saying Trump's campaigning for Saccone "turned what was a deficit for the Republican candidate to what is essentially a tie."

Lamb's victory is somewhat symbolic.

Under a state court order in a gerrymandering case, the seat is one of Pennsylvania's 18 U.S. House districts whose boundaries will change next year, and the new ones will be in play in this year's mid-term elections.

Even before Tuesday night's vote, Saccone was making plans to seek the nomination in a different district in May's primary, a new southwestern Pennsylvania district that leans solidly Republican without the Pittsburgh suburbs that helped Lamb.

Neither Saccone nor Lamb lives in that district, but Saccone is planning to run there since, under the new boundaries, Saccone's home is in a Pittsburgh-based district that is heavily Democratic and home to longtime Democratic Rep. Mike Doyle.

Lamb is expected to run in a new district west of Pittsburgh against Republican Rep. Keith Rothfus. That district is far less friendly to Republicans than Rothfus' existing district and is described by Republicans as a toss-up.