A former legislator unseated a state senator Tuesday, by just 169 votes.

State Sen. Kevin Avard, a Republican from Nashua, was seeking a third term in office. He’s also previously served one term in the N.H. House.

Democrat Melanie Levesque of Brookline, a businesswoman and former state representative, won the race, 12,553 to 12,384, according to results from the Secretary of State's office Wednesday.

That gives Levesque 50.3 percent of the vote — leaving the difference between the two candidates at less than 1 percent.

Rindge is the only local community included in the Senate district, which stretches along the Massachusetts border and covers Brookline, Greenville, Hollis, Mason, New Ipswich and Nashua Wards 1, 2 and 5.

Avard won a solid majority in Rindge, with 60.17 percent of the vote.

He also saw a hefty lead in New Ipswich, but he lost all three wards in his hometown to Levesque, closing the gap.

Levesque served three terms in the N.H. House, representing her hometown along with Hollis and Mason from 2006 to 2010 and 2012 to 2014. She’s the president of TCS America Enterprises, a communications consulting company, and serves on the Hollis-Brookline Cooperative School Board.

Levesque has said she believes the government has a responsibility to provide broadband access to rural communities, and that comprehensive health care is the solution to the opioid epidemic. She’s also put a focus on public education.

Avard pushed his support for school choice, Gov. Chris Sununu’s veto of two energy-related bills over the summer, and keeping taxes low.

This article has been changed to update final results in the race.