A Brooklyn teenager was sentenced on Tuesday to 19 years to life in prison for having set fire to a mattress in a hallway of his apartment building, resulting in the death of a police officer who responded to the blaze.

The young man, Marcell Dockery, sat still and silent in State Supreme Court in Brooklyn as Justice Danny K. Chun issued the sentence after scolding him for having killed the officer, Dennis Guerra, and having gravely injured his partner, Officer Rosa Rodriguez. “The saddest thing about this case,” Justice Chun said, was that the two officers had responded to the fire “because of their love for the job and their love for helping people in trouble, and because of that, Officer Guerra is dead.”

After a two-week trial in April and May, Mr. Dockery, now 18, was convicted of murder, assault and arson. The officers went to the apartment building, at 2007 Surf Avenue in Coney Island, after receiving a report about the fire on April 6, 2014. When the two entered the lobby, they saw no sign of flames and took an elevator to the 13th floor. Prosecutors introduced surveillance video at the trial of the thick black smoke that awaited them, and Officer Rodriguez testified that she had been unable to breathe in the hot, chaotic scene.