City Council Speaker Corey Johnson apologized Monday for retweeting a story about the number of people shot and killed by cops in the US compared to the UK — just after a city detective was shot dead by friendly fire in a Queens robbery.

“American police shot and killed 998 people in 2018. In the UK, in the deadliest year of police shootings in the last 14 years, only six people were killed by police,” Johnson posted on his Twitter account on Thursday.

He deleted it soon thereafter — but not before it was spotted by the city’s Police Benevolent Association.

“@NYCSpeakerCojo care to explain this? Deleting the offensive tweet is not enough. The problem is the reflexive impulse to denigrate the police officers who work every day — and sometimes sacrifice their lives — to protect this city,” the PBA wrote Thursday, two days after the Queens tragedy.

Johnson issued an apology when contacted by The Post.

“The Speaker is rightly concerned about deaths by firearms, which is why a story about the number of fatal police shootings was shared on his official Twitter account. But it was a mistake to do so on a day when our city was mourning the death of Detective Brian Simonsen and praying for the recovery of Sgt. Matthew Gorman,” a Johnson spokesperson said in a statement.

“The tweet was quickly deleted. He is sorry if this caused pain to members of law enforcement at a time when they — and all New Yorkers — were rightly focused on remembering the heroism of Det. Simonsen and the ultimate sacrifice he paid to keep us safe.”

Johnson also spoke Monday to Paul DiGiacomo, vice president of the Detectives Endowment Association, and apologized about the tweet coming so soon after the death of one of its members.

Johnson is attending Simonsen’s wake and was at Jamaica Hospital to show support the night of the shooting.

Simonsen responded to a report of a robbery in a smartphone store last Tuesday and was killed in a tragic incident of friendly fire. His funeral is Wednesday.