It happened near the hospital's trauma center on Wednesday at about 4:20 p.m.
Authorities identified the inmate as 35-year-old Thaddeus Lewis, who is charged with aggravated assault against a public servant.
According to the Houston Police Department's Homicide Division Special Investigations Unit, the deputy was guarding Lewis, who was at the hospital for a doctor's appointment, and escorted him to the restroom.
While in the restroom, Lewis attacked the deputy, leading to a struggle, HPD said.
During the fight, authorities said Lewis grabbed the deputy's gun, and it went off.
The deputy was shot in his left hand. According to authorities, four hospital staff members acted fast and helped detain Lewis.
Investigators said the injured deputy is a 36-year veteran of the department.
Lewis was transported back to the Harris County Joint Processing Center.
CHARGED: Booking photo of the suspect, Thaddeus Lewis, 35, now charged with aggravated assault against a peace officer in yesterday's shooting inside a hospital.— Houston Police (@houstonpolice) July 15, 2021
More info is at https://t.co/eSQ80cQImM #hounews https://t.co/8W6fSw3Shh pic.twitter.com/o4YQUBPBnz