A New York City police officer shot and killed a 69-year-old man who wielded a machete inside a South Bronx apartment on Tuesday morning after officers burst inside searching for drugs and a firearm, the police said.

Another man, in his 90s, who was inside the apartment, at 230 Brook Avenue in Mott Haven, was not injured, the police said. A friend said the man had thought the officers were robbers when they broke down the door, so he stayed in bed, fearful of being hurt.

“He thought it was a robbery,” said the friend, Ronald Perez. “He said he would have gotten up if he knew it was police.”

The dead man was identified by the police as Mario Sanabria.

The shooting, which unfolded at about 4:10 a.m. inside the third-floor apartment, was the third time in recent weeks that city police officers opened fire on people wielding knives inside the close quarters of residential spaces. The Police Department has been expanding its efforts to train officers to de-escalate encounters with civilians who are not armed with a gun and to avoid deadly force when possible.