Cops say the teen pointed this revolver at undercover officers before they opened fire. (NYPD)

Undercover cops fatally shot a teenager in Brooklyn last night after he pointed a loaded gun at an officer, police sources and witnesses said.

Kimani Gray, 16, was shot in the leg and stomach when he whipped out a .38-caliber revolver after adjusting the waistband on his pants, said cops.

The two undercover officers, driving a red umarked car, had approached the group of teens because they were acting suspiciously on East 52nd Street near Snyder Street in East Flatbush just before 11:30 p.m.

Gray was rushed by ambulance to Kings County Hospital, only a few blocks away. But doctors could not save his life.

Cops later recovered the .357 revolver, which had four bullets in its cylinder.

When the two cops arrived at the scene, Gray was standing on the sidewalk with five friends.

As the cops opened fire, “he was screaming, ‘Stop! I’m not running,!’ ” said pal Devonte Brown, 16.

Neighbors confirmed a rapid succession of gunfire booming through the area. “I heard a lot of shots, rapid fire, about eight shots,” said one resident. “I heard the gun shots from my living room.”

As the bullets struck Gray, he grabbed his side and began yelling, witnesses said.

The teenager’s friends refused to say exactly what prompted the cops to fire.

Police sources said one of the officers involved in the shooting was a sergeant, who fired multiple bullets.

Gray had a rap sheet that included charges of grand larceny and inciting a riot, police sources said.