NEWPORT, N.H. — A New Hampshire man told a judge on Tuesday that he gunned down his wife in front of their 3-year-old son in a spasm of anger after learning she was having an affair with a former student.

James Perriello, 42, pleaded guilty to second-degree murder and admitted he shot Natalie Perriello, a popular teacher at Lebanon High School and a finalist for the state’s teacher of the year competition, several times on April 26, 2012. Perriello said he had secretly taped her and discovered the affair.

In court on Tuesday, he said he was “very angry” the night he killed his wife. He told Judge Brian Tucker he was “very sorry” for what he had done.

As he spoke in court, Natalie Perriello’s brother, Bob LaFlam Jr., stared at him.

“I just couldn’t believe … what he did to those kids,” LaFlam said after Perriello pleaded guilty.

James Perriello’s parents declined to comment. The couple’s four children, ages 3 to 12 at the time of the shooting, are being raised by Natalie Perriello’s mother.

Prosecutors will ask for 35 years to life in prison when he is sentenced Dec. 18, while Perriello’s lawyer, Kimberly Cossick, will seek 18 to 36 years in prison.

The Perriellos had marital problems for years that got worse after the birth of their fourth child, according to court records. They had separated several months before the shooting but eventually returned home, sleeping in separate bedrooms.

They went to a counselor on the day of the shooting. Police said on the night of the shooting, Perriello continued confronting his wife about what he had heard on the recording.

Police learned through the recording that Natalie Perriello, 42, and her 20-year-old former student “were affectionate toward one another and had initiated a relationship.” Perriello also told police he had been monitoring his wife’s email, social media sites and text messages.

Perriello initially told police he went back into the bedroom with a gun to scare his wife and that it accidentally went off when she tried to grab it. He said the gun had a hair-trigger but a police expert testified it fired normally.

Only subscribers are eligible to post comments. Please subscribe or to participate in the conversation. Here’s why.

Use the form below to reset your password. When you've submitted your account email, we will send an email with a reset code.