Just minutes after a New Hampshire man was sentenced to prison for sexually assaulting a four-year-old girl, he was headbutted in the Dover courtroom by another prisoner, in an attack that was caught on video.

WMUR-TV reports Christopher Elwell, 29, was sentenced on Thursday to 7 ½ years to 15 years in prison and has to register as a sex offender for his crime.

As he sat down after his sentencing, a shackled and handcuffed Josiah Davies smashed into Elwell's head with his own head multiple times.

Scroll down for video

Pedophile: Christopher Elwell, 29, was sentenced on Thursday to 7 ½ years to 15 years in prison for sexually assaulting a four-year-old girl

Elwell was sitting on a bench in court when another prisoner, Josiah Davies, lunged at him and headbutted him multiple times (left and right). Both men were shackled and handcuffed

Quick reaction: The Strafford County deputy sheriff immediately pulled Davies off of Elwell and subdued him

The station caught what happened on video; Elwell did not appear to be injured and seemed impassive.

The Strafford County deputy sheriff immediately pulled Davies off of Elwell, dragged him to the other side of the bench and subdued him.

Davies, 27, was awaiting arraignment and a hearing on a probation violation.

The Strafford County Attorney's Office said the two men did not know each other prior to the altercation and that it must have been something about Elwell's case that set Davies off.

The New Hampshire Union-Leader reported that Elwell was accused of sexually assaulting the four-year-old during a sleepover in Dover back in late June.

Not impressed: Elwell was not injured and appeared impassive after the altercation

Sick crime: Elwell (left) was accused of sexually assaulting the four-year-old during a sleepover. Josiah Davies' (right) alleged crime was passing fake checks

He initially denied any wrongdoing, but on Thursday pleaded guilty to aggravated felonious sexual assault and failing to register as a sex offender.

The latter charge stemmed from a 2008 conviction for engaging in sexual acts with a 14-year-old. Elwell was 20 years old at the time.

Davies, a transient man from Rochester, was in court for allegedly violating the terms of his probation in a forgery case, reported Foster's Daily Democrat.

The 27-year-old has been charged with 17 felony counts for allegedly passing fake checks to the tune of nearly $9,000.

The county sheriff's office is investigating Thursday's courtroom attack. Davies could be looking at up to seven years in prison.