What started as a minor arrest in a Brooklyn nail salon spun wildly out of control Friday night — leaving a cop fighting for his life from head injuries after shooting dead a berserk, mentally-ill T-shirt vendor who’d struck him in the face with a chair, police said.

The officer, a 21-year-veteran of the force whose name was not released, remained in a medically induced coma early Saturday, authorities said.

The mayhem began at about 5:40 p.m. when a panhandler walked into the Goldmine nail salon on Mother Gaston Boulevard near Sutter Avenue in Brownsville and began urinating in the shop.

The NYPD veteran and his rookie partner happened to be passing by in a patrol van, and were waved inside the store by disgusted workers.

But as the two cops arrested the alleged urinator — who also had an open warrant for criminal mischief — a T-shirt peddler from outside the shop burst in and confronted the officers, police said.

The peddler, identified by sources as Kwesi Ashun, 33, of Brooklyn, suffered from schizophrenia and bi-polar disorder, his sister said; he had been arrested in 2004 for allegedly slashing a cop in the face in Flatbush, a law enforcement source said.

In Friday night’s incident, Ashun grabbed a chair during a struggle and swung it into the head of the veteran cop, NYPD Chief of Patrol Rodney Harrison said.

The rookie officer zapped Ashun with a Taser during the melee, but it didn’t slow his attack, police said.

So the veteran cop managed to pull his service weapon despite his own serious injuries, firing at Ashun six times and hitting him at least once, in the head, authorities said.

Medics rushed the injured officer to Brookdale Hospital.

Ashun was declared dead at the scene and the rookie officer was brought to Kings County Hospital to be treated for ringing in his ears.

Ashun peddled t-shirts he designed and hand-embroidered himself, according to an Instagram page promoting his wares.

In the now-sealed 2004 arrest, Ashun allegedly slashed a passing foot-patrol officer from his left ear to his neck, then walked away.

He had a kitchen knife and a folding knife in his possession, and had to be subdued with pepper spray before he could be arrested, The Post and the New York Times reported at the time.

In 2008, police had additional contact with him because he was emotionally disturbed, a source said Friday.

Ashun’s family members and other supporters rushed to the scene of his shooting, some sobbing and railing against the NYPD.

A young man wearing an ID for ThriveNYC — the city’s embattled mental health initiative — around his neck was also at the scene, holding a briefcase and standing with the family members.

“He struggled with mental illness and we tried desperately to get help for him to no avail,” said his sister, Ama Bartley, 35.

Ashun had an Oct. 14 appointment with a mobile crisis team from the city Department of Health, the sister told The Post.

But health workers determined after a short visit that he was not a threat to himself or others, she said.

“Eleven days later, this is what happens,” she said. “We tried, we really tried to get him help. He was a beautiful soul. He was just battling some heavy things.

Pat Lynch, head of the Police Benevolent Association, railed against the latest attack on a police officer during a press conference after the shooting.

“This police officer spent his career in our busiest precincts serving the community. And he was set upon. For no reason!” he said.

Residents of the neighborhood described the shot man as a fixture on the block, an entrepreneur who worked hard making and selling his hand-crafted T-shirts.

State Assemblywoman Latrice Walker happened to be walking near the shop before the scene unfolded, and was even approached by the vendor for a sale.

“I interacted with him moments before this took place. He asked me if I would be interested in buying the T-shirts he was selling,” Walker told The Post.

“He was always a peaceful young man,” Walker added of the man who was killed. “He was promoting a business he was trying to kick off.”

Walker was near the store with her young daughter when the shots were fired.

“Gunshots rang out,” she said. “It was five o’clock – kids were leaving after school – it was mayhem. Children were running, families were afraid – my daughter was screaming,” she added.

“It was in a blink of an eye.”

Additional reporting by Tina Moore, Alex Taylor and Laura Italiano