San Francisco firefighters work a triage area near the scene of a shooting at a UPS facility.

UPS workers gather outside the San Francisco warehouse after the shooting.

An armed UPS employee killed three colleagues before turning the gun on himself inside a massive distribution center in San Francisco on Wednesday, police and witnesses said.

The shooter was wearing the company’s distinctive brown uniform when he gunned down three co-workers and wounded two other colleagues, witnesses and officials said.

And when he saw SFPD officers coming, the killer turned the gun on himself and pulled the trigger, police said.

“One contact team (of responding police officers) located the suspect who was still armed with an assault pistol,” said San Francisco Assistant Police Chief Toney Chaplin.

“The suspect put the gun to his head and discharged the weapon. Officers secured the weapon and immediately administered aid to the suspect.”

The shooter was identified as San Francisco resident Jimmy Lam, according to multiple local media reports.

Cops said they need to interview dozens of witnesses before saying what his motive might have been.

One co-worker told KGO-TV that Lam didn’t get along with his boss, saying he “had it out for a manager.”

The gunman was still alive and was rushed to San Francisco General Hospital, where he was pronounced dead.

The UPS center employs 850 people.

“It could have been worse,” said Mayor Ed Lee, lauding cops for a fast response to the 8:55 a.m. shooting. “Lives were saved today.”

Two weapons were recovered from the gunman, said Chaplin, who declined to elaborate on the killer’s potential motive.

“We believe the incident involves only one suspect,” Chaplin said. “At this point, we do not believe this incident is related to terrorism.”

Police hadn’t identified any of the victims, even seven hours after the shooting.

But family and friends told local media that one of the dead was 46-year-old driver Mike Lefti, who had three children.

“He was a nice guy,” said Jaime Sandoval, a friend of the Lefiti family. “I’ve known him since I was a kid. Every time I see him, he was always nice. A cool dude. He had a lot of respect and love for his family. I’m just pretty shocked.”

Cousin Bob Toia said Lefti was always generous.

“He would always give the shirt off his back,” Toia told the San Francisco Chronicle. “He was a real dedicated person to his family, to his wife, to his kids. If you needed anything, Mike was there for you. He was always there for you.”

At least two bodies were spotted in the middle of 17th Street and San Bruno Avenue, covered with yellow tarps.

SFPD officers blocked off several streets around the center at 320 San Bruno Ave. — in San Francisco’s Potrero Hill neighborhood, about 2½ miles south of downtown.

“We understand that there are potentially multiple deaths,” UPS spokesman Steve Gaut said. “Our thoughts and prayers are with all those touched by this incident.”