A man was fatally shot by police on Manhattan’s Upper East Side Thursday night, police sources said.

Shots rang out around 7:20 p.m. near E. 96th St. and Madison Ave., police and witnesses said. Police canvassed the area after getting reports 20 minutes earlier of a man with a gun near E. 107th St. and Madison Ave., and then spotted the suspect on Madison Ave. between E. 96th and E. 95th St., according to authorities.

“It was a 20-year-old man,” a police source said. “He shot first at one of our officers,” who returned fire, striking him, the source said.

The suspect was taken to Mount Sinai Hospital in critical condition, and later died, according to multiple police sources.

“I saw it. It was a scuffle over by the bus stop,” said witness Layla Helou, 26. “There were police officers telling someone to stop. He pulled out a gun and started shooting. It was a close range sort of thing.”

“It was about nine gunshots,” said Malay Greshwell, 24, who works nearby.

“I saw him lying on the ground. He was on his side. He was bleeding. He was leaking. It looked like he was shot in the head,” Greshwell said of the gruesome scene. “The cops were looking at him to see where he was wounded before they put him on a stretcher.”

“I was petrified. I’ve never seen anything like this before,” added Greshwell, who lives in the Bronx.

“I pulled my son by his shirt, and we sat down behind a big wall and waited it out,” said bystander Jonathan Trichter. “It happened so fast. The cars were definitely in pursuit.”

Trichter’s 11-year-old son, who was walking with his dad, recounted, “I heard shots. At first I thought it was fireworks.”

“I saw the police cars coming out and turning off of Madison,” the boy continued. “But then I realized it wasn’t fireworks. It was gunshots, six gunshots. We took cover.”

A gun was recovered at the scene, police said. The man’s identity was not immediately released.

The NYPD Force Investigation Unit is investigating.