A rookie NYPD officer just out of the Police Academy became the first city cop shot on duty this year when he was wounded in a Brooklyn parking lot Wednesday.

Officer James Li, 26, was hit multiple times in the leg, groin and thigh outside a White Castle restaurant at Utica Avenue and Empire Boulevard in Flatbush, law-enforcement sources said.

“I was like boom boom boom. I would say close to 20 shots, if not more,” said James Zitis who darted across the street from his Affordable Glass shop.

“I saw the cop down in the driveway of the White Castle parking lot, shot in the left leg.”

Two off-duty EMS workers — Khadija Hall and Shaun Alexander — rushed to aid the fallen officer as cops chased the suspect.

“These two women were like angels,” said Asad Penkale, who lives in the neighborhood.

“They rushed over and started working on the cop. He looked like he was in a lot of pain.”

The incident unfolded when two officers pulled Rashaun Robinson, 28, and another suspect off an MTA bus after they boarded without paying.

Robinson, who has multiple prior arrests, started to run and both Li and Officer James Chow gave chase.

Police said Robinson then turned and fired a .45-caliber Smith & Wesson from about 10 feet away, hitting Li multiple times.

Both officers returned fire but Robinson was not hit.

Witnesses pointed cops toward an apartment building on Schenectady Avenue where Robinson was found cowering in the fifth-floor hallway.

Cops said the suspect had the firearm in his waistband and authorities recovered three shell casings at the scene.

He was taken to the 71st Precinct station house and charges were pending Wednesday night.

Li was rushed to Kings County Hospital, where he was in stable condition. He had wounds to the left leg, right thigh and groin.

His wounds were not believed to be life-threatening.

“They did everything a good cop does and did it like seasoned veterans,” Police Commissioner Bill Bratton said at the hospital.

Mayor de Blasio also visited the hospital and said he was “proud of the NYPD and what they do everyday.”

Li was in the most recent Police Academy graduating class and was assigned to the 71st Precinct just a few weeks ago.

The last officer to be shot in the line of duty also was a rookie wounded in the leg in Brooklyn.

Last July, Officer Jamil Sarwar, 30, and his partner were on foot patrol in the Cypress Hill Houses and pursuing a suspect in a gang shooting when Sarwar was hit by a sniper from the housing project’s roof.

The last officer killed in the line of duty was Peter Figoski, who was responding to a Brooklyn robbery in December 2011.

With additional reporting by Dana Sauchelli