In the summer of 2013, as he sought to cement his legacy as a three-term mayor of New York, Mike Bloomberg faced a pair of threats to his signature — and highly divisive — crime-fighting policy, known as stop-and-frisk.

One challenge was in the courts, where a mostly black group of New Yorkers who'd been subjected to the pat-downs accused the city of systematic racial profiling. The other was in the New York City Council, where lawmakers wanted to hold police accountable for complaints of abuse.

The dual challenges to stop-and-frisk marked an escalation in public resentment over the tactic, which focused aggressive policing in largely minority neighborhoods with high crime rates but fueled claims that it did more harm than good in those communities.

Bloomberg scorned the critics.

"I think we disproportionately stop whites too much and minorities too little," Bloomberg told a radio interviewer early that summer, arguing that stop-and-frisk targeted the people who were committing most of the city's gun violence.

When a federal judge ruled that the police department's use of stop-and-frisk violated minorities' rights and ordered oversight by a court-appointed monitor, Bloomberg — a lifelong Democrat who became a Republican to run for mayor and switched to independent while in office — vowed to keep stop-and-frisk going through his final days in office. When the council voted to enact the reform measures, he vetoed them, called them "dangerous to the city" and tried to sink attempts to override the veto.

The Rev. Al Sharpton leads the way as protesters call for an end to the New York Police Department's stop-and-frisk policy in 2012. Andrew Savulich / New York Daily News via Getty Images

"He fought us every single step of the way," recalled Jumaane Williams, a Democrat who at the time was a City Council member pushing the reforms. He is now the city's public advocate. "Everywhere we turned, the mayor and people who supported him kept telling everyone that we were going to handicap the police department and destroy the city."

More than six years later, as Bloomberg campaigns for president as a Democrat, that response is noteworthy again. As a candidate, he says that he now regrets defending the NYPD's use of stop-and-frisk for so long and that he did not understand the pain it caused minority New Yorkers at the time. But the policy remains a consistent focus of criticism as he seeks the party's nomination, cited by his Democratic opponents, President Donald Trump, civil rights activists and people who were subjected to the policing tactic.

"We let it get out of control," Bloomberg said when challenged on the issue again Tuesday at the Democratic debate in South Carolina, where several of his opponents called his deployment of stop-and-frisk racist. Bloomberg is not on the ballot for the state's primary Saturday, but he is on it in more than a dozen states holding primaries Tuesday. "And when I realized that, I cut it back by 95 percent. And I've apologized and asked for forgiveness."

The apology came only recently, just before Bloomberg entered the race. For years before, he championed stop-and-frisk as a proven method to prevent shootings and other crimes. His recent campaign comments also gloss over the fact that the decline in the use of stop-and-frisk came only after it ballooned to historic levels under his watch and opposition reached a tipping point, according to half a dozen people who were involved in the fight at the time.

Stop-and-frisk was not Bloomberg's idea. The tactic — in which officers stop and pat down any person "reasonably" suspected of being involved in a crime — has been used by New York police since the 1960s, when it was first permitted under city law and was upheld by the U.S. Supreme Court. Bloomberg's predecessor as mayor, Rudy Giuliani, a Republican, embraced it in the 1990s, and it was divisive even then. A 1999 report commissioned by state Attorney General Eliot Spitzer found that the NYPD stopped and frisked minorities disproportionately and often failed to meet the legal threshold of reasonable suspicion.

After taking office in 2002, Bloomberg greatly expanded the program.

An analysis of police data by the New York Civil Liberties Union — which joined the federal lawsuit that claimed the NYPD was stopping and frisking people without reasonable suspicion — found that its use increased by more than 600 percent, from 97,296 stops in 2002 to a peak of 685,724 stops in 2011, just before the lawsuit was filed. The vast majority of people targeted in the searches weren't charged with crimes.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

In 2012, the NYPD made a series of changes to its stop-and-frisk policy, including a reminder to officers to avoid racial profiling, and Bloomberg announced his intention to continue the stops but with "civility." Stops began to decline, and the next year, when a federal judge ruled the NYPD's use of stop-and-frisk unconstitutional, the number tumbled to 191,851.

New York police arrest a man in a subway in 2012. Orlando Camargo / Third Eye Corporation/Flickr Vision/Getty Images file

Since then, under Mayor Bill de Blasio, who won office on a promise to curtail stop-and-frisk, the stops have trended downward, but they rose last year by more than 20 percent, from 11,008 in 2018 to 13,459 in 2019, according to the NYPD.

While in office and in the years afterward, Bloomberg tied stop-and-frisk to historic drops in crime, even though the downturn persisted with the decline of stop-and-frisk.

Download the NBC News app for breaking news and politics

There is no clear data proving the effect of stop-and-frisk on crime; the causes of New York's decadeslong drop in crime remain debatable. Some researchers have found that stops based on clear suspicion of criminal activity contributed, but that wasn't the case with stops in which officers couldn't articulate specific reasons to search someone.

"They twisted the law in order to essentially carpet-bomb neighborhoods," said Jeffrey Fagan, a Columbia Law School criminologist who conducted two studies of the effectiveness of stop-and-frisk in New York and analyzed data for the plaintiffs in the federal lawsuit. "But when they were much more careful and judicious and rigorous, they were actually good at deterring crime."

Bloomberg continued to justify the use of stop-and-frisk as recently as October, when he told The Washington Post that the tactic made the city safer.

"I came into a situation where an awful lot of people were killing an awful lot of other people. And it was all pretty much one community," Bloomberg was quoted as saying. "And I just said, 'We are going to do anything we can to stop the carnage.' The first thing was stop the murders. And we brought down the incarceration rate in jails by a third, mostly minority kids. We brought down the murder rate by 50 percent, from 600 to 300 murders, and you know who would have been killed."

A month later, preparing to enter the presidential race, Bloomberg said in a speech at a black church in Brooklyn that he came to see the damage stop-and-frisk did to black and Latino communities and how crime continued to fall when the tactic was reduced.

"I now see that we could and should have acted sooner and acted faster to cut the stops," Bloomberg said. "I wish we had — and I'm sorry that we didn't. But I can't change history. However, today, I want you to know that I realize back then I was wrong — and I am sorry."

With Bloomberg newly contrite, many of those who challenged him over stop-and-frisk say voters now considering whether to support him for president should know how aggressively he resisted.

"He didn't just keep going ─ he dug in, tried to stop reforms, appealed the judge's ruling and fought the bills," said Monifa Bandele, who sits on the board of the Communities United for Police Reform Action Fund, a coalition of New York advocacy organizations. "He could have been like 'I'm going to just leave,' but he dug in and fought us all the way to his last day in office."

The new scrutiny has also revived feelings of anxiety and anger in many neighborhoods that were targeted during the height of the policy, Bandele said.

"Living through stop-and-frisk, it was horrible," she said. "If your loved one didn't come home or you didn't know where they were for a while, your first thought was: They must have been stopped by police. People lost jobs if they got caught up over the weekend in Rikers. They lost custody of their kids. It was horrible."

A police officer trains in stop-and-frisk procedure at an New York police training facility in the Bronx in 2012. Mark Bonifacio / New York Daily News via Getty Images

In the spring of 2013, as the federal lawsuit was approaching a final ruling, the City Council debated a package of bills aimed at fighting stop-and-frisk: one that would create an inspector general's office to monitor the police department and another that would make it easier for people to sue the agency for discriminatory policing. Bloomberg vowed to veto them, so supporters worked to find 34 members willing to vote yes ─ the number needed to override a veto. Some recalled council members' telling them they feared retaliation from Bloomberg or his administration, including the possibility that the billionaire mayor would finance an opponent.

But the bills passed ─ and, as promised, Bloomberg vetoed them. He warned that the measures "could reverse the striking, dramatic and wonderful reduction in crime this city has experienced over the last 10 years or 20 years."

With that began a second battle over the 34 votes needed for an override.

"There was a coordinated campaign with mailers and phone banks trying to get council members to switch sides," said council member Brad Lander, a Democrat who helped shepherd the bills to passage. He has endorsed a Bloomberg rival, Sen. Elizabeth Warren, D-Mass.

That fight was underway when U.S. District Judge Shira Scheindlin ruled on Aug. 12, 2013, that the NYPD's use of stop-and-frisk was unconstitutional and blamed Bloomberg and his police commissioner, Raymond Kelly, for officers' feeling pressure to increase stops.

Bloomberg, outraged, accused Scheindlin of anti-police bias. In a column in The Washington Post, he said she had showed "disdain for our police officers and the dangerous work they do." And he vowed to appeal so stop-and-frisk could continue.

"I wouldn't want to be responsible for any people dying," The New York Times quoted him saying.

A few days after the ruling, the council overrode Bloomberg's veto. He vowed to sue the council to block the measures "before innocent people are harmed."

The lawsuit did not succeed, but Bloomberg's appeal of the court ruling allowed the city to pause the reforms ordered by Scheindlin. That ended in 2014, when de Blasio, his successor, withdrew the appeal.

Before he knew who the next mayor would be, Bloomberg told The New Yorker that he hoped that person wouldn't back down on stop-and-frisk.

"Stop-and-frisk has been shown to be — not the only, but the most effective, tool in getting guns out of the hands of kids," he said.

Williams, the City Council member, said the battle over stop-and-frisk revealed the problem of having a wealthy mayor who, while immune to outside influences, didn't feel the need to listen to critics, including his most vulnerable constituents.

"There was nothing to show this man that he was wrong," said Williams, who has endorsed one of Bloomberg's rivals, Sen. Bernie Sanders, I-Vt. "He bought into it in a way that was remarkable. And it had a lasting effect."