A police officer was shot and wounded Thursday night while patrolling the Cypress Hills Houses, a project in East New York, Brooklyn, the police said.

The officer, who was not immediately named, was on foot patrol at around 10:54 p.m. when he was shot in the right leg, the police said. The officer was taken to Jamaica Hospital Medical Center in stable condition, and his injuries were not considered life-threatening.

The shot appeared to have been fired from one of the houses, possibly from a rooftop, the police said. In the immediate aftermath of the episode, it was not clear whether the officer was targeted or was hit by random gunfire.