A man, who was being detained at the Croydon Custody Centre in south London, opened fire on the officer in the early hours of Friday morning.
The officer, whose name was not made public, was treated at the scene and taken to hospital where he died.
“This is a truly shocking incident in which one of our colleagues has lost his life in the most tragic circumstances,” London police chief Cressida Dick said.
The gunman, then shot himself, according to a Scotland Yard statement.
“A 23-year-old man was detained by officers at the scene. He was also taken to hospital with a gunshot wound and remains in a critical condition,” it said.