WORCESTER, Mass. — A former Massachusetts police officer convicted of kicking a handcuffed and shackled prisoner was sentenced Wednesday to two years of probation by a judge who took into account his military service.

Ex-Worcester officer Michael Motyka was also ordered to continue treatment for the post-traumatic stress disorder he has suffered from since his time in the Army.

Motyka, 52, was convicted at a bench trial in June of assault and battery with a dangerous weapon for kicking Gerald Jones in December 2014.

“Mr. Motyka has served his country admirably in the United States Army and incurred a service-related injury, post-traumatic stress disorder, as a result of his service in Operation Desert Storm,” Worcester Superior Court Judge Richard Tucker said.

The judge also factored in the fact that Motyka had no prior criminal record, and that the victim’s injuries were not serious.

The 17-year police veteran lost his temper after Jones yelled profanities and racial insults, prosecutors said. Motyka is white and Jones is black.

“He should have walked away instead of letting the victim’s words get under his skin,” prosecutor Gina Masotta said.

Motyka testified that he entered the cell because he thought Jones had a weapon and acted in self-defense when Jones, 50, attacked first.

The entire episode lasted 18 seconds. There was no camera in the cell at the time, although one has since been installed.

Motyka, who retired in 2015, is likely to lose his pension and health insurance, said his lawyer, James Gribouski.

Jones received a $225,000 settlement from the city in connection with the case.

Jones did not appear in court for sentencing and Motyka did not speak.