A Burnsville cop who testified in court this week that he exchanged racist e-mails with a man accused of shooting at Black Lives Matter protesters resigned from his department on Thursday.

Officer Brett Levin’s decision to step down capped a dramatic day in the trial of Allen Scarsella, the 24-year-old charged with felony riot and assault in connection with wounding five black men protesting the death of Jamar Clark in November 2015.

Levin took the stand on Tuesday to explain that when Scarsella called him the night of the shooting, he urged Scarsella to turn himself in. Levin testified that the two were friends since high school, and that he frequently received “racially charged” e-mails from Scarsella that were “negative about black people.”

He said he replied to Scarsella with similar texts.

“How we were talking was more of along the lines of locker room talk,” he explained to the jury when asked why he exchanged the texts. “So I guess that would be my answer, it’s just in the moment you’d say something like that.”

He was not asked about the content of his texts and declined to comment after his testimony Tuesday.

After Levin’s testimony, Burnsville Police Chief Eric Gieseke said the department “has very high standards regarding the conduct and professionalism of our officers. We are proud of our reputation and relationship with all of our diverse community members.”

Two days later, Gieseke said Levin resigned. Levin, 24, could not be reached for comment. Since joining the department last May after serving as a police officer in Mankato, Levin had no formal complaints against him, Gieseke said on Tuesday.

Scarsella’s friend testifies

Also Thursday, Scarsella’s friend and co-defendant, Nathan Gustavsson, took the stand to testify for the defense.

Gustavsson, 22, along with Daniel Macey, 27, of Pine City and Joseph Backman, 28, of Eagan, stand charged with second-degree riot and aiding an offender.

Against the advice of his attorney, Bob Jones, Gustavsson waived his Fifth Amendment rights as part of his testimony.

“There’s nothing I can do to protect you,” Jones warned Gustavsson before he took the stand.

“Yes I understand that,” Gustavsson replied.

Gustavsson told the jury that he knew Scarsella through an internet message board 4Chan, and that the two were gun enthusiasts.

Before going to the protest on Nov. 23, Gustavsson sent texts to Scarsella saying “I know how to make big news or get them to disperse” and “I could rile so much [expletive] up.”

Gustavsson told a jury that he wanted to livestream the protest on Nov. 23, similar to what Scarsella and another man, Julio Suarez, did a few nights earlier. In those videos, Scarsella and Suarez wore masks to the protests, saying they wanted to do “reverse cultural enriching” and “make the fire rise.”

After those videos went viral, protesters testified that the mood of the camp became tense, and that anyone covering their face or wearing a mask would be asked to remove it.

Gustavsson and the other three had their faces covered when they went to the protest. They stood along a fence when someone approached them asking what they were doing there, Gustavsson said. They responded that they were livestreaming. Soon after, more protesters gathered around the four men, eventually surrounding them. Gustavsson said they were asked to take their masks off but didn’t. He said the protesters became agitated and started screaming at them.

Gustavsson said that he saw Scarsella get punched, then Backman threw his hands in the air in a sign of surrender and told the crowd they were leaving.

As they were walking away, Gustavsson said he was punched from behind, knocking him to the ground, breaking a tooth and bruising his face.

His testimony was cut short by the end of the day, and he did not talk about Scarsella firing his gun. It is expected to resume Friday.