NYPD Commissioner Ray Kelly admitted that cops target blacks and Hispanics for the city’s controversial “stop and frisk” program to keep guns off the street, a state lawmaker testified this morning.

State Sen. Eric Adams, D-Brooklyn, said Kelly made the startling admission during a July 2010 meeting in Manhattan with then-Gov. David Paterson and other officials.

Adams, a former NYPD captain, said he complained that a “disproportionate” number of blacks and Hispanics were being subjected to the controversial crime-fighting program.

According to Adams, Kelly “stated that he targeted or focused on that group because he wanted to instill fear in them that any time they leave their homes they could be targeted by police.”

Adams said he was “amazed” and “shocked” by Kelly’s alleged remarks, adding: “I told him that was illegal.”

He said Kelly responded by asking: “How else are we going to get rid of guns?”

The judge in the “stop and frisk” trial this morning invited NYPD Commissioner Ray Kelly to take the witness stand and testify about the controversial crime-fighting program.

During cross-examination, city lawyer Heidi Grossman tried to read from a written declaration in which Kelly denied making the remarks, but was blocked by the judge, who called it a “back door” method of admitting testimony from the city’s top cop.

Manhattan federal Judge Shira Scheindlin then publicly invited Kelly to take the stand, saying: “If he’d like to come here, he’s welcome in this courtroom.”

The NYPD didn’t immediately respond to a request for comment.

Plaintiffs in the case sought to use Kelly as a witness for their class-action suit, which claims the NYPD illegally targets minorities for stops and seeks the appointment of a court-ordered monitor.

But Kelly was barred from testifying after the city refused to schedule a pre-trial deposition on grounds that he’s “too busy” running the NYPD, plaintiffs’ lawyer Jonathan Moore said.

Moore said the plaintiffs would probably oppose any last-minute attempt to have Kelly testify, saying: “In civil cases, you’re not allowed to do trial by ambush.”

Moore also said Kelly would likely only offer testimony that had been “scripted” for him by city lawyers.