IOWA CITY, Iowa (AP) — A judge has condemned an Iowa police chief for using his city-issued stun gun to shock guests at two parties in 2016, calling it an “immoral activity” that could have caused serious injuries or death.

Judge Nancy Whittenburg recently rejected arguments by Craig Merrill, the police chief in Armstrong, that his deployment of the Taser device in an off-duty, social setting against voluntary participants was not a criminal act.

“Merrill did not have justification to use a defensive weapon with the intent to cause pain for entertainment purposes on compliant partygoers,” Whittenburg wrote in a ruling dated May 27.

Noting that the weapon is capable of causing injuries ranging from burning skin to death, she added, “Merrill is exceptionally lucky that no one suffered a medical emergency or died at the party.”

Merrill was charged in February with two counts of assault with a dangerous weapon for using the stun gun against Armstrong’s then-maintenance director Tylor Evans and several others who attended parties at Merrill’s home in April and July 2016.

“Defendant Merrill announced that he knew he was ‘not supposed to do this,’ attempted to prevent partygoers from documenting the crime, and told partygoers he would lie to the City Council about whether the TASER darts had been deployed,” prosecutors said in a recent filing.

Prosecutors say Merrill collected $30 from guests to pay for the city to replace the cost of the gun’s cartridge but never deposited the funds.

At a second gathering around July 4, Merrill admitted that he had shocked everyone who attended multiple times using the device’s drive-stun function, which delivers electrical shocks as a method of pain compliance, prosecutors allege.

Merrill also allegedly tried to erase the device’s memory before it was seized by investigators, but a state official was able to extract data showing bursts of activity on the dates of the parties.

Authorities arrested Merrill in February along with his father-in-law, then-Armstrong mayor Greg Buum, and former city clerk Connie Thackery, in what prosecutors have described as a long-running and wide-ranging corruption scheme in the town of 900 people. Two other former city clerks have pleaded guilty and are cooperating with investigators.

Prosecutors say Merrill, 43, collected $24,000 in unused paid time off to which he was not entitled and accepted a free vacation in 2017 to the Black Hills in South Dakota paid for by his political supporters in violation of state law. He’s also charged with ongoing criminal conduct, first-degree theft and non-felonious misconduct in office. The city placed Merrill on unpaid administrative leave after his arrest and is relying on the Emmett County sheriff’s office for policing services. Buum has resigned as mayor.

Attorneys for Merrill had asked the judge to dismiss the assault charges. They argued that Evans had signed a document consenting to be stunned and that Merrill’s use of the stun gun during a voluntary social activity was legal under an exemption to the assault law for contact sports.

Whittenburg rejected those arguments, writing that consent is not a defense to assault and “TASERing will never be considered a proper sport or social activity.” She noted that the exemption for sports activities only covered assaults that are “reasonably foreseeable” and do not create unreasonable risks of injury, neither of which applied in this case.

“Typical birthday party attendees do not expect the hired clown or magician to start electrocuting and incapacitating people,” she wrote.

She said that while the drive-stun function in which the device is pressed against the body may seem safer than shooting electrical probes from a distance, it still carries the risk of burning and permanently scarring skin.

Whittenburg also rejected arguments that the charges were barred by the statute of limitations.

Merrill, Buum and Thackery have pleaded not guilty to the charges, and an Aug. 20 hearing has been scheduled to set a trial date. They are all free on bond.