Judges have been given powers to hand down stiffer sentences on people who assault police or prison officers.
The new law passed by Parliament late Wednesday night also covers attacks on firefighters, paramedics, doctors and nurses while they are attending emergencies.
Justice Minister Judith Collins' bill makes assaults on those officers and emergency workers an aggravating factor in sentencing.
"It means every judge must consider the fact that an assault on them is an aggravating factor when sentencing the offender," she told parliament.
"At present there is no requirement on the court to take special notice of that."
Ms Collins said they all worked in dangerous situations and the government recognised they needed special protection.
In its original form the bill only applied to police and corrections officers and it was a Labour Party amendment, accepted by the government, that extended it to emergency workers.
The bill passed its third reading on a vote of 117 to four.
The Maori Party and the Mana Party voted against it. MPs from those parties didn't speak during the third reading debate.
NZN