It happened about 3:40 a.m. inside the detention center's sally port, which is designated for the Magistrate, off W. Pettigrew Street at S. Roxboro and S. Mangum streets.
Authorities said the incident happened as Durham Police Officer R.S. Turner brought 44-year-old Danny Lee McMillen of Durham into the booking area. McMillen was originally arrested about 2 a.m. when officers responded to a peeping call on Chesden Drive.
According to a preliminary investigation, as Officer Turner removed McMillen's handcuffs, he saw that McMillen was reaching for a gun in the back of McMillen's pants.
Authorities said Officer Turner immediately tried to grab the gun, but McMillen refused to let go. As the two wrestled over the gun, the gun went off one time, grazing Officer Turner's abdomen. He was taken to the hospital for treatment. He was later released. McMillen was not injured.
Despite detention officers not providing security in the Magistrate's area - before entering the secure area, each law enforcement agency provides its own security - a detention officer did assist Durham police in taking McMillen back into custody.
The firearm, a .380-caliber handgun, was also recovered. The incident is being investigated by the Durham Police Department's Criminal Investigations Division.
A spokesperson also said the Professional Standards Division will "be reviewing the incident to determine if proper departmental policies and procedures were followed."
This isn't the first time in Durham a suspect has been taken into custody while still armed.
In 2013, 17-year-old Jesus Huerta fatally shot himself while in the back of a patrol car with a gun authorities failed to find after a physical search.
RELATED: Report on teen's shooting death while in Durham police custody
McMillen has been charged with misdemeanor secret peeping, assault with a deadly weapon on a government official, assault with a deadly weapon with intent to kill, carrying a concealed weapon (firearm), possession of a weapon by a prisoner and discharging a firearm within the city limits.
Officer Turner joined the department in January 2014. Officials say officers in the recruit academy receive training in search procedures.