Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

A federal judge in North Carolina, a battleground state in the presidential election, ruled Friday that state officials illegally dropped voters from the registration lists and must restore them.

Judge Loretta Biggs said the right to vote "cannot be sacrificed when citizens through no fault of their own have been removed from the voter rolls."

She ordered the state to reinstate the registrations that were canceled, stop further purges of the registration lists, and make sure that voters denied an absentee ballot are given the option to get one or vote in person.

According to data compiled by the state, nearly 6,700 challenged voters were removed from registration lists in eight counties over the past two years. Most were in Cumberland County, which includes Fayetteville.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Related: Obama Slams N.C. Republicans for Alleged Voter Suppression

A conservative group called the Voter Integrity Project used a variety of data mining techniques, looking for signs that voters had moved and should no longer be on the rolls. They then invoked the state challenge process, and county election officials sent notices to challenged voters, giving them a chance to respond. Those who did not were dropped.

Related: Election 2016: Tracking Reports of Voting Problems Across the United States

But the judge said Friday that many of the affected voters didn't know about the hearings, because the counties sent notices to the same address as the unreturned mailing that supported the challenges.

On Monday the NAACP filed a lawsuit claiming that the practice violated a federal law that allows a registration to be canceled only if a voter either confirms a change of residence in writing or is sent a notice and fails to vote during two federal elections.

The law also blocks systematic voter removal programs within 90 days of an election. The judge sided with the NAACP on both claims.

Voters in the affected counties, she said, "should be treated on election day as though no challenge ever occurred."

The NAACP said minority voters were targeted "in coordinated, en masse challenge proceedings brought in the final weeks and months before election day, and whose right to vote has been challenged solely on the basis of a single piece of undeliverable mail."