A man was headbutted by a prisoner in a New Hampshire courtroom Thursday after the man was sentenced to prison for sexually assaulting a 4-year-old girl, video showed.

Christopher Elwell, 29, was sentenced in a Dover courtroom to 7 ½ to 15 years in prison and has to register as a sex offender. The assault occurred in June when the victim went to a house where Elwell was residing for a sleepover, WMUR-TV reported. Two other children, aged 4 and 9, were also at the residence at the time.

MURDER VICTIM’S FRIEND STEALS FUNERAL FUNDS TO BUY CAR, POLICE SAID

Elwell told officers he was with the victim watching porn in a room when the young girl asked to do what the people in the video were doing.

It was not immediately clear what Elwell’s relationship was to the children.

As Elwell attempted to sit down after his sentencing, Josiah Davies got up and headbutted the felon multiple times, WMUR-TV reported.

JUDGE: DOCTOR WHO DOESN’T USE COMPUTER CAN’T REGAIN LICENSE

The news station caught the interaction on tape and Elwell did not appear to be injured.

Davies was shackled and awaiting arraignment and a hearing on a probation violation. His court was rescheduled to Dec. 4 due to the fight.

The Strafford County Attorney's Office said the two didn't know each other and that it must have been something about Elwell's case that set Davies off.

The county sheriff's office was investigating the incident.

The Associated Press contributed to this report.