A lawyer with no experience in the criminal justice field unseated three-term incumbent Republican Dennis Hogan to be the next Hillsborough County Attorney, a job that puts him in charge of most felony criminal prosecutions in the state’s largest county.

Michael Conlon, a Democrat, had 77,819 votes vs. 76,161 for Hogan, a margin of about 1,700 votes, or a single percentage point.

“A lot of Democrats voted,” Hogan said on Wednesday afternoon, not long before the Secretary of State posted the results.

Hogan, a Republican, lost his home city of Nashua and the state’s largest city, Manchester. He prevailed in suburban towns such as Bedford and Hudson.

No one signed up in the Democratic Party primary for the county attorney position.

The party filled the empty slot with Conlon after the primary, which is allowed under state law. Conlon’s campaign included social media posts and lawn signs.

This was a high-profile year for Hogan.

In the spring, he took his budget fight public, warning his office was on the brink of collapse because of under-funding. In the summer, Attorney General Gordon MacDonald’s office said it was taking a “360-degree” review of the office, citing Hogan’s leadership style.

And this fall, news broke that hundreds of indictments could be at risk because a judge allowed the spouse of one of his employees to sit on a grand jury.

Hogan attributed most of the problems to under-funding and an increase in workloads attributed to the Felony First program.

Conlon, 37, praised Hogan for his three terms as county attorney.

The Democrat said he was licensed to practice law in 2010 and has been working in the regulatory compliance field for move than 10 years. He said he will use that experience — which often involves dealing with companies in a crisis because of regulatory failings — to address shortcomings in the County Attorney’s office under Hogan.

“It seems like they could benefit from more business management, crisis management and organizational leadership,” Conlon said. He said he has never worked in criminal law.

Hogan had scant experience in criminal law when he was first elected.

This is the first partisan election for Conlon. He was elected to the Goffstown Planning Board.

He attributed the win to the enthusiasm of Democrats, the independent vote and criticism about Hogan’s performance from police, defense lawyers and advocacy organizations.

The state’s largest county, Hillsborough comprises 31 towns and cities and is divided between urban and suburban communities in the east and rural towns in the west.

In another countywide race, veteran Sheriff James Hardy, a Republican, defeated Bill Barry, a Manchester alderman, 48 to 47 percent, with 4 percent for Aaron Day, who ran as a Libertarian.

This is the fourth time that Barry has tried to unseat Hardy. Barry said he decided to run after the filing period, so he had to mount a write-in campaign to get on the ballot.

“It only gave me seven weeks to prepare and campaign,” he said. Barry also said Day may have been a spoiler. In tallies that Barry reviewed on-line, he said he was about 100 votes or so behind other Democrats running for county positions.

“What’s the common denominator? I had a third (party) guy,” he said.

In other contested races, Democrat Paul Bergeron defeated Michael Soucy, 53 to 47 percent, for a county commissioner seat in the Nashua area. Republican Robert Rowe defeated Steve Spratt for the western-towns seat, 51 to 49 percent.