London Metropolitan Police said the officer was shot dead at Croydon Detention Center in the south of the city just after 2 a.m. He was taken to a local hospital where he was pronounced dead.
The 23-year-old detained man is in critical condition in a hospital.
The force said no police weapons were fired.
Police officers are rarely shot and killed in the UK, which has strict gun laws.
Prime Minister Boris Johnson and other senior politicians said they were shocked by Friday’s death.
“We owe a huge debt to those who risk their own lives to keep us safe,” Johnson said.
London Mayor Sadiq Khan said: “My heart goes out to the family of this brave officer, who paid the ultimate price for helping keep Londoners safe. ”
“When a colleague dies in the line of duty, the shockwaves and sadness reverberate throughout the Met and in our communities,” said Metropolitan Police Commissioner Cressida Dick. “Police are family, in London and nationwide, and we will all mourn our colleague deeply. ”
The force has opened a murder investigation, and the independent police watchdog is also investigating.
The last London police officer killed in the line of duty was Constable Keith Palmer, who was stabbed to death in March 2017 in a car and knife attack outside Parliament.