TORONTO -- Ontario's police watchdog has cleared a Toronto officer after a man was shot in the ankle during a police raid this spring.

The Special Investigations Unit says it appears the 23-year-old man accidentally shot himself with the officer's gun while trying to fend off police.

The SIU says police had a warrant to search the apartment for firearms just before midnight on April 24 and the authority to temporarily detain the occupants.

It says the Toronto police emergency task force broke down the door and called for the occupants to leave before going inside and removing those who stayed inside.

The agency says the man seemed asleep and didn't respond to officers' commands, then "put up a significant amount of resistance when he was woken up," prompting them to Taser him.

The SIU says the officer switched the safety toggle on his machine-gun to the "off" position and had it dangling from a sling on his chest when he approached the man, who then grabbed it.

"At that point, the weapon discharged, with a projectile striking the complainant in the left ankle," the agency said.

Forensic tests later found the man's blood on the flashlight attached to the gun, it said.

"It is clear that there was contact between the complainant and the firearm based on the (Centre of Forensic Sciences) blood analysis," SIU director Ian Scott said in a release Friday.

"On this basis, the complainant's firearm injury was probably the result of an accidental discharge caused by himself, and not by the subject officer."

The SIU is an arm's-length agency called in to investigate whenever someone is seriously hurt or killed while interacting with police.