An NYPD officer testified Thursday that he feared he was going to be shot when he kicked open the door to a Bronx apartment where 18-year-old Ramarley Graham was then shot dead by the cop’s partner, Richard Haste.

Testifying at Haste’s departmental trial, officer John McLoughlin of the 47th Precinct said that he kicked open the second floor apartment door because he believed an armed Graham was inside.

“I was afraid I was going to get shot,” said McLoughlin. “I believed there was a man inside with a gun.”

McLoughlin was called as a defense witness by Haste’s attorneys in an effort to show Deputy Commissioner for Trials Rosemarie Maldonado that their client was not the cop who kicked open the door in possible violation of police procedure and that other officers believed Graham was armed.

Maldonado is presiding over the administrative trial in which the NYPD is asking for Haste’s termination because of his alleged “poor tactical judgment” during a police chase which ended in Graham’s death on February 2, 2012, at his home on East 229th Street. In testimony early this week, other officers who were part of the street narcotics unit pursuing Graham and two other men said they also believed Graham was armed when they followed him to his home.

McLoughlin testified that he saw Haste enter the apartment and that Graham “ran” toward the cop as the officer repeatedly said “show me your hands.” Haste followed Graham into a bathroom, at which point the officer yelled “gun, gun,” — words followed by a single gunshot, said McLoughlin.

At the end of the trial, Maldonado can recommend to Police Commissioner James O’Neill that Haste be fired or can suggest a lesser penalty. Haste is scheduled to testify Friday, along with one additional defense witness, said attorney Stuart London.

The defense presented witnesses Thursday in an effort to show that it was McLoughlin — and not Haste — who breached the apartment door and that police supervisors didn’t give Haste or his partner any direction during the quickly unfolding events.

Sgt. Scott Morris, who supervised the unit, admitted that the cops weren’t in the required regular uniform during the operation but that higher up supervisors approved the mode of dress, which was civilian clothes, NYPD raid jackets and police shields.

Morris said two officers in his unit had reported that Graham had a gun and that he asked one of if he was certain he spotted a weapon. When asked by defense counsel Michael Martinez why he asked the officer for verification of a weapon, Morris answered “I wanted to be sure, I don’t want to ruin somebody’s day for no reason.”

Morris said that Haste told him right after the shooting of Graham that “Sarge, I saw him reach,” referring to the teen.

When Morris was cross-examined by a department lawyer about why he didn’t call for an emergency services unit as called for under police procedure, he answered that he didn’t believe it was a barricade situation, which required an ESU response.

Morris and McLoughlin both have been separately hit with administrative charges by the NYPD and face departmental trials later.

Graham’s family and his mother, Constance Malcolm, are attending the trial. The family had settled a claim against the city in 2015 for almost $4 million.

Haste was indicted by a Bronx grand jury for manslaughter charges in 2012 but the case was dismissed. A second grand jury declined to indict him and federal prosecutors decided to bring no charges against Haste.