Metropolitan Police launched a murder investigation following the shooting by a 23-year-old man being detained at Croydon Custody Centre in south London at around 2:15 am (0115 GMT).
The suspect was also taken to hospital with a gunshot wound and remains in a critical condition, the force said, but added that no police firearms were discharged during the incident.
Police did not say how the suspect was shot, though the Evening Standard newspaper said he shot himself
British police are not routinely armed, although forces have tactical firearms units to respond quickly to incidents. Deaths in service are also rare.
“This is a truly shocking incident in which one of our colleagues has lost his life in the most tragic circumstances,” said Metropolitan Police Commissioner Cressida Dick.
“My heart goes out to his family, direct colleagues and friends.
“When a colleague dies in the line of duty the shockwaves and sadness reverberate throughout the Met and our communities. We will all deeply mourn our colleague.”
Fiona Bone and Nicola Hughes were the last British police officers to be shot dead in the line of duty, when they were ambushed in a gun and grenade attack in September 2012.
They were killed by drug dealer Dale Cregan while responding to a report of a burglary in Manchester, northwest England.
Since then, a further five officers have been killed on duty — four by
vehicles while pursuing suspects and one, Keith Palmer, who was stabbed during the 2017 terror attack on parliament.