A man thought he was doing nothing wrong when he casually lit up a joint in an Oregon courthouse last month -- until cops intervened.

The man had come into the Multnomah County courthouse on July 21 to watch a hearing regarding the shooting death of a 17-year-old boy at Portland park, the Oregonian reported.

Surveillance video released Monday by the sheriff's office shows the man lighting up before being confronted.

Related stories...

Deputies told FOX12 the man lit his joint and sat down in the back row of the courtroom.

Officials told the man he couldn't smoke in courthouse, and when deputies got closer they smelled the scent of marijuana.

When the man was told to leave he asked "why?" and was then informed by deputies he was not allowed to smoke marijuana in public.

The man eventually cooperated with deputies and tamped-out the joint in a nearby trash can, but the courtroom smelled like marijuana even after he left, FOX12 reported.

Oregon has legalized recreational marijuana since July 1, 2015, but the law only allows people to smoke in their private homes.