A man who stabbed himself in Wellington District Court is in a stable condition following an operation on Tuesday.
The 29-year-old, whose name is suppressed, will spend the night in Wellington Hospital's intensive care unit under police guard.
The man faced 32 charges of possession of indecent publications and was sentenced to a six-month jail term on Tuesday morning.
As he was being escorted from court by two police officers, the man pulled a knife from inside his sock and began slashing at his neck.
He was given first aid at the scene before an ambulance rushed the critically injured man to hospital.
In a statement, the Justice Ministry says a court security officer recognised the man as someone who had attempted to harm themselves before in a police cell.
A court official says the man had been remanded at large before the sentencing and was not considered to be a special threat.
In May, $9 million of operating funds were allotted in the Budget to gradually upgrade court security over the next four years.
Minister for Courts Georgina te Heu Heu says it is hoped the first of the refurbishments will begin in September - and Wellington District Court will be among the first to benefit.