Terence Hallinan, a onetime teenage brawler who became a fighter for civil rights and then an against-the-grain politician, serving as a San Francisco supervisor and the city’s district attorney, died Friday. He was 83.

“He passed away this morning, in his sleep, peacefully,” his son, Brendan Hallinan, told The Chronicle.

Hallinan gained the nickname “Kayo” from his prowess as a boxer — he was on the boxing team at UC Berkeley and nearly made the U.S. Olympic team in 1960 — and from his pugilistic tendencies that led to a criminal record and almost cost him his legal career. It took a state Supreme Court ruling in 1966 to overturn the State Bar’s decision that the 30-year-old was morally unfit to practice law.

Thirty years later, after his election as district attorney, prominent developer Joe O’Donoghue said Hallinan slugged him at a restaurant where O’Donoghue had berated him for firing the son of a business partner, in a post-election office purge intended to shake up and diversify the office. The two reconciled shortly afterward with prodding from newly elected Mayor Willie Brown.

Hallinan also fought the status quo.

He was beaten and arrested as an antiwar protester and civil rights demonstrator in the 1960s. As a supervisor from 1988 to 1995, he was an early sponsor of transgender rights and a supporter of decriminalizing prostitution. As San Francisco’s top prosecutor for the next eight years, he hired women, minorities, gays and lesbians in unprecedented numbers, sought alternatives to prosecution for nonviolent crimes and declined to seek the death penalty for any capital cases — a practice his successors, Kamala Harris and George Gascón, continued.

“I’ve shown that you can be a tough prosecutor and still be true to your progressive ideals,” Hallinan said in 2003 after Harris, a former prosecutor in his office, defeated him in his bid for a third four-year term. Harris has gone on to become California’s attorney general and a U.S. senator.

“His storied legal career was intertwined with so much of our great city’s history,” Mayor London Breed said in a statement. “He was outspoken and fierce in his pursuit of justice, his defense of those in need, and his love for this city.”

Hallinan had radical roots. His father, Vincent, a renowned defense lawyer, ran for president on the Progressive Party ticket in 1952 from jail, where a judge had sentenced him for contempt of court during his defense of union leader Harry Bridges.

Hallinan grew up in a mansion in Marin County. At age 12, on a camping trip near Yosemite National Park, he fell off his horse, fractured his skull and was stranded for five days before being rescued by helicopter.

As a member of what the district attorney described as a “wolf pack,” Hallinan had at least six run-ins with the law between ages 16 and 22. A juvenile court judge convicted him of theft and battery at age 17. He pleaded guilty to assaulting the owner of a Sierra ski lodge at 18. And he was charged with felony assault for breaking a young man’s jaw at 22, but the jury deadlocked.

“I was a tough guy — in those days, people said, the toughest guy in Marin County,” Hallinan recalled in a 1995 interview. “I had a lot of anger.”

After graduating from UC Berkeley in 1960, he attended the London School of Economics and was arrested again — but this time for taking part in a nonviolent protest, a sit-down near the U.S. Embassy as part of a disarmament demonstration led by philosopher Bertrand Russell.

While studying law at UC Hastings in San Francisco, he spent the summer of 1963 registering black voters in Mississippi as a member of the Student Nonviolent Coordinating Committee and was arrested and beaten by local police. He joined further protests in San Francisco with the NAACP, the Congress of Racial Equality and other civil rights groups. He was arrested six times in 1963 and 1964 and was twice convicted of unlawful assembly and disturbing the peace during sit-ins against auto dealers’ racial practices.

Hallinan graduated from Hastings in 1964 and passed the bar exam, but the bar’s Committee of Bar Examiners found that he lacked the “good moral character” required of lawyers, citing his violent past and numerous arrests. In a December 1966 ruling, however, the state’s high court said Hallinan had renounced violence since joining the civil rights movement, and he had not shown disrespect for the law as a protester.

If California disqualified from its licensed professions everyone who had been convicted of crimes for engaging in nonviolent civil disobedience, “we would deprive the community of the services of many highly qualified persons of the highest moral courage,” Justice Raymond Peters said in the 6-1 decision.

Hallinan worked as a private lawyer for nearly three decades. His clients included soldiers who were being held as prisoners in the San Francisco Presidio in 1971, in some cases for their opposition to the Vietnam War and for holding sit-down protests over stockade conditions.

He also represented the Diggers, a late-1960s Haight-Ashbury group that ran a free store on Haight Street but ran afoul of the police when they held a poetry reading and food giveaway on the steps of City Hall in 1968. The criminal charges, which included defaming the U.S. flag after one member wore a stars-and-stripes shirt, were quickly dismissed.

In 1978, Hallinan took up the case of Juan Corona, who had been convicted in 1971 of murdering 25 farmworkers. Arguing that Corona’s trial lawyer should have told jurors about his client’s schizophrenia, the attorney persuaded a state appeals court to overturn the convictions. Hallinan then represented Corona at his second trial in 1982, when Corona was again convicted and sentenced to life in prison.

Hallinan also served briefly on the defense team for newspaper heiress Patricia Hearst in her bank robbery case.

He entered politics in 1977, running for the Board of Supervisors, but lost to gay-rights leader Harvey Milk. Hallinan was elected on his third try a decade later.

After eight years as a member of the board’s progressive wing, he launched a surprising candidacy for district attorney in 1995, telling one interviewer that defense lawyers and prosecutors practice the same law. He defeated veteran attorney Bill Fazio with 52% of the vote, despite opposition from police and prosecutors’ groups, as well as major local newspapers.

Among his first acts as district attorney was to fire 14 longtime prosecutors, including the son of developer O’Donoghue’s business partner. It was the beginning of a series of personnel moves that gave women and racial minorities a combined majority on Hallinan’s staff.

Criticizing what he called the “revolving door of incarceration,” Hallinan expanded the office’s programs of supervision and rehabilitation as an alternative to punishment for nonviolent crimes, and steered juvenile offenders into training and treatment programs. And after declaring himself “America’s most progressive district attorney,” he squeaked through to re-election in 1999, again beating Fazio by 1,800 votes out of more than 200,000 cast.

But the felony conviction rate plummeted to just above 50%, among the lowest in the state, during his tenure. Hallinan, in explanation, noted that violent crime was also plunging in San Francisco, faster than it was dropping statewide, and attributed the drop in convictions in part to his alternative rehabilitation programs and the city’s liberal jurors.

When he told The Chronicle in 1998 that he suspected the slaying of an organized crime figure was related to the unsolved killing of Hallinan’s former campaign finance manager, an irate judge removed the district attorney’s office from the crime figure’s murder case, and the State Bar privately reprimanded him.

Perhaps his highest-profile case, known as Fajitagate, ended in legal and political embarrassment.

After three off-duty police officers allegedly beat a man for refusing to hand over a bag of steak fajitas in 2002, Hallinan accused the Police Department of a cover-up. He secured a grand jury indictment against seven senior officers — including Police Chief Earl Sanders and Assistant Chief Alex Fagan, whose son was among the three officers on the scene — for allegedly obstructing justice.

But Hallinan soon dropped the charges against Sanders, admitting he could not prove the chief was part of a conspiracy, and a judge dismissed charges against the other senior officers. The three off-duty officers were acquitted at a criminal trial, although a civil jury later ordered Alex Fagan Jr. and a second officer to pay damages. The case widened the gulf between the police force and Hallinan, contributing to his 12-point defeat to Harris in December 2003.

Hallinan returned to private law practice, teaming with his son, Brendan Hallinan, and specializing in medical marijuana cases. He remained largely out of public view, but in December 2014 the State Bar effectively ended his legal career with a 90-day suspension for using a bank account he had designated for clients’ funds as his personal account. No clients were harmed, but the misconduct was “willful,” said the bar’s disciplinary court.

In a statement Friday, Hallinan’s family said: “Terence was a visionary in the battle for social, economic and racial equality in the United States. A fierce advocate for the underdog, he fought for justice for the most vulnerable members of society and worked to reform the criminal justice system. Terence was a pioneer in the decriminalization of cannabis laws and the treatment of substance abuse as a public health issue.”

Former Supervisor Tom Ammiano recalled his former board colleague as a true San Franciscan, unbowed by any criticism or popular opinion.

“I just loved and admired him,” Ammiano said. “I served on the Board of Supervisors with him, and I learned so much about government from him. He fit that San Francisco template of being very colorful. He was pugnacious — literally — he had been a boxer. He took on a lot of causes that were not very popular. He had that San Francisco bite, and he was also brilliant. When he became D.A., he was also under attack from the police union, from your newspaper. And he took the heat in the Hallinan way: It made me more resolved and more outspoken.”

Hallinan is survived by his wife, Lisa, daughters Savoy, Audrey and Vivian, son Brendan, and five grandchildren.

Chronicle staff writer Dominic Fracassa contributed to this report.

Bob Egelko is a San Francisco Chronicle staff writer. Email: begelko@sfchronicle.com Twitter: @egelko