The suspect killed by a Hillsborough County Sheriff's deputy Wednesday evening was shot while selling drugs during an undercover operation.

According to the sheriff's office, Robert Earl Gary, Jr., got into a fight with an undercover deputy during a drug deal at an apartment complex near 122nd Avenue and 16th Street in Tampa.

Officials said Gary, 31, was killed. The deputy suffered non life-threatening injuries and is recovering at home.

Authorities said the undercover deputy was buying crack cocaine Wednesday at 5:30 p.m. when Gary tried to rob the deputy. The two men started to fight, and the deputy lost his handgun. Backup deputies rushed in to help and fatally shot Gary.

According to officials, Gary has a long arrested record, with previous charges like grand theft, selling cocaine and aggravated assault with a deadly weapon. Gary, whose arrest record goes back more than 10 years, had spent time in prison.

Officials are investigating specifically how Wednesday's shooting unfolded.

"It's unknown at this time who actually fired those rounds because of the struggle," said HCSO Col. Donna Lusczynski. "Backup deputies moved in and shot the suspect. They saw the deputy in a fight for his life, shot the suspect."

The Sheriff's Office is not releasing the deputy's name because of his undercover status. All three deputies involved will be placed on administrative leave until an internal investigation is completed.

That is standard procedure from the sheriff's office.

Gary's criminal history includes nearly a dozen arrests since 2001 and 27 arrests as a juvenile, according to the Hillsborough County Sheriff's Office. He was released from prison in August.