The man who tried to take the deputy's weapon was shot and killed inside the hospital. Fayetteville Police identified him as Treva Smutherman, 31, of the 6000 block of Pence Drive in Fayetteville.
The incident started at 8:22 a.m. in the emergency department.
Authorities said that the suspect was picked up by police on Tuesday night for active warrants.
WATCH: 'Boom, Boom, Boom:' Woman in hospital describes scary ordeal
After his arrest, he started experiencing medical problems and was taken to Cape Fear Valley Medical Center for treatment.
While at the hospital, the suspect reportedly tried to take the deputy's weapon.
During that scuffle, the deputy was shot in the leg. A Fayetteville police officer who was also at the hospital opened fire on the suspect, killing him.
"Of course it could have been a lot worse," said Fayetteville Police Sgt. Jeremy Glass. "I don't know the intentions of the suspect other than just shooting the deputy but of course it definitely could have been a lot worse."
According to the sheriff's office, the deputy is in good condition. The sheriff visited him in the hospital and said he was up and talking.
"I am thankful to our law enforcement for the way in which they handled and returned the hospital premises to safety," Fayetteville Mayor Mitch Colvin said.
A woman who asked to be identified as Miss Scott gave her account of the early morning Wednesday shooting inside the Cape Fear Valley Medical Center.
"I heard 'pow' and I was like, 'I know that wasn't, like, what I thought it was," Scott said.
Scott said she heard a woman screaming and someone calling for security, and that's when she realized the situation was more serious.
"Then another lady came by and she told everybody to stay in the rooms and she went by and closed everybody's doors," Scott added.
The Fayetteville resident, who had her father checked into the hospital for medical problems Tuesday evening, then proceeded to shield her bedridden father.
"Finally, after that, there were three more shots after that and it was like 'boom, boom, boom,'" she said.
About 15 to 20 minutes later, the hospital announced the suspect has been stopped.
"I was like oh my goodness, I hope this isn't a mass shooting. What in the world is going on?'" she said.
Hospital officials later notified patients of the situation.
Cape Fear Valley Medical Center is back open and doctors are available to see patients. However, people who do not have business at the hospital are being asked to stay away.
This morning there was active shooter in Cape Fear Valley Medical Center Emergency Department. The situation is contained. There is no longer an active shooter. All hospital visitors should have identification and the name and room number of the patient they are visiting.— capefearvalley (@capefearvalley) November 6, 2019
The State Bureau of Investigations is now in charge of the case, which is standard protocol for officer-involved shootings.