A complaint affidavit from the Broward County, Fla., Sheriff's Office said Cruz assaulted the guard unexpectedly at the Fort Lauderdale jail Tuesday. The guard said Cruz struck him and took away his stun gun.

The affidavit said Cruz discharged the weapon as the officer tried to wrest control of it.

Officials said video of the incident confirmed the assault, and showed Cruz on top of the guard as they scuffled on the floor. The sergeant hit Cruz once he got the weapon back, the affidavit says.

"Cruz retreated to one of the seats located in the Dayroom area, at which point Beltran was able to take him into custody," it reads.

Cruz was charged Wednesday with assault on an officer, battery of an officer and obstructing police.

Cruz is also charged with 17 counts of murder and 17 counts of attempted murder in the Feb. 14 attack at Marjory Stoneman Douglas High School in Parkland. If convicted, he could receive the death penalty.