David Oster, right, leaves Gallatin County District Court on Tuesday after pleading guilty to obstructing justice, a misdemeanor.

A Belgrade man pleaded guilty Tuesday to charges that he hid a gun that was used in a video to threaten other students.

David Oster pleaded guilty to obstructing a peace officer, a misdemeanor. He appeared in Gallatin County District Court before Judge Holly Brown.

Oster was initially charged with felony tampering with evidence last summer. As part of a plea agreement, prosecutors agreed to drop the felony charge and recommend that Oster receive a six-month deferred sentence at his sentencing next month.

In June, police responded to Belgrade High School to investigate a report of a video posted to social media depicting students threatening other students with a gun, according to charging documents. The video showed three girls and a boy kicking, punching and yelling racial slurs at the camera. In the video, they said they were going to beat other students, and a boy cocked the gun several times.

Officers found the four students and took them to the Belgrade Police Department for questioning. They told officers that the video was made at Oster’s house and that they used his gun to make the video, court documents say.

Deputies went to the house to retrieve the gun and met with Oster. Police said in charging documents that Oster told officers that the gun wasn’t at the house, but later he said he dropped the gun in a portable toilet at a construction site.

Deputies found the loaded gun there, and Oster was taken to the Belgrade Police Department. Oster admitted hiding the gun after seeing the video, police said. He said he felt guilty and irresponsible that others were able to get his gun and thought he needed to get rid of it.

In court on Tuesday, Oster admitted he knew his gun was used in a video that police were investigating and that he hid it.