Paul Iannuccillo beat incumbent Robert Kelley in the Democratic primary for Northern Essex Register of Deeds by 1576 votes.
Iannuccillo received 4,675 votes while Kelley trailed with 3,099 votes.
Iannucillo now faces Republican Jack Wilson and independents Brian Corrigan and Stephen Battle in the Nov. 6 final election.
In North Andover, where he lives, Iannuccillo took 1103 votes to Kelley's 422. Iannuccillo also won in Methuen, receiving 1982 votes while Kelley trailed with 544.
The race was close in Lawrence with Kelley receiving 1376 votes and Iannaccillo 1320. Kelley also win in Andover, his hometown, taking 757 votes and Iannuccillo earned 270 votes.
First elected six years ago to political office, Kelley, an attorney, was sharply criticized for spending time off the job. He was the subject of a Fox 25 news report in 2011 that showed him working at his private law office, running errands and going to a bar on state time.
Iannuccillo, 49, a father of three, is a former Lawrence City Councilor, state representative and current counsel to the House of Representatives.