The victim, Jamil Sarwar, is expected to recover. (Christopher Sadowski)

Police visit the scene of Thursday’s shooting. (William Miller)

Two people are being questioned over the sniper shooting of a rookie NYPD cop outside a Brooklyn housing project last night, sources said.

Last night, hundreds of cops descended on the Cypress Hills Houses and put the area on virtual lockdown as they searched door-to-door for the gunman who shot Officer Jamil Sarwar in the thigh, just above the knee, sources said.

“He was shot by a sniper,” said a law-enforcement source.

Around 10:45 pm, an officer in an elevated surveillance tower saw two people shooting at each other on Sutter Avenue, the northern border of the houses, NYPD Commissioner Ray Kelly said in a press conference last night.

“They pursued the individual thought to be involved in the original shooting … but they lost him,” Kelly said.

Sarwar and his partner Javier Solos — who were on foot patrol nearby — also responded and were inside the housing complex when they heard two to three shots fired, Kelly and sources said.

“They go into 365 Fountain to take cover. When they are inside, they realize that officer Sawar had been shot in the right thigh,” Kelly said.

Law enforcement sources said they believe the gunman intentionally targeted Sarwar and Solos.

“They were standing together. It’s a well-lit area. They had to know they were shooting at cops,” a law enforcement source said.

Sarwar — a Bangladeshi native who joined the force in 2012 — was taken to Jamaica Hospital with a single gunshot wound and was expected to recover.

“He’s very lucky. He could have been struck at any part of his body and the other officer with him also could have been struck,” Kelly said.

The Brooklyn North Impact officer was in good spirits last night — his parents and siblings rushed to his bedside — as doctors tried to determine if the bullet should be removed, Kelly said.

Cops believe the gunshot came from an apartment window at the housing complex, or possibly from a rooftop.

Investigators found 9mm and 40-caliber shell casings — four in all — on a rooftop as well as on the ground, sources said, but it was not known if they were related to Sarwar’s shooting, Kelly and sources said.

“I heard some yelling and someone said a cop got shot,” said resident Gabe Falton, 52. “And then cops just flooded the area. I have never seen so many cops. They’re looking for some guy shooting down on the cop like a sniper.”

About 60 police cars, nine NYPD crime-scene trucks, and helicopters arrived at the housing project in a massive effort to find the shooter.

Adding to the chaos, firecrackers from Fourth of July revelers continued to explode around the housing project’s grounds well past midnight, rattling already jittery neighbors.

The housing project is known for its violent gang activity, a source said.

“The Bloods live in the front houses and the Crips live in the back and side houses, and they’ve been having a running feud,” the source noted. “They’re looking at both gangs.”

Investigators are probing whether the shooting was gang-related and whether Sarwar was the intended target.