Joe Biden, Kamala Harris, Cory Booker, Kirsten Gillibrand and six other candidates took the stage in Detroit. (Video: The Washington Post)

DETROIT — Former vice president Joe Biden, attempting to regain his footing by adopting a more aggressive and combative posture during a Democratic presidential debate here Wednesday night, faced relentless attacks on his decades-long Senate record on race and criminal justice, immigration and health care, and his commitment to women’s rights.

The exchange showcased many of the deep divides within the party that are taking on greater urgency as the candidates strive to make gains before the field narrows.

Standing between Sens. Kamala D. Harris (Calif.) and Cory Booker (N.J.), Biden swiveled back and forth as his record on and commitment to issues of race were questioned in increasingly pointed ways. Later, Harris and Sen. Kirsten Gillibrand (N.Y.) teamed up to criticize his positions on working women and abortion.

Who talked the most during the second Democratic debate

“Everybody’s talking about how terrible I am on all these issues,” Biden said at one point. “Barack Obama knew exactly who I was. He chose me and he said it was the best decision he made.”

But the former president’s legacy also faced frequent scrutiny, as candidates sought to a remarkable degree to distance themselves from his administration’s trade policies and record of deporting millions of undocumented immigrants, and to promote proposals that could dismantle his signature health-care law.

Biden was eager to remind voters of the stature he built over nearly five decades of public service — and to shed the image of him as the halting and lackluster candidate he was in the first debate, in June — by vigorously challenging his opponents’ records. But they were just as sharp with him, drawing attention to his age — 76 — and to positions he still defends.

“There’s a saying in my community,” Booker told Biden amid a discussion about criminal justice. “You’re dipping into the Kool-Aid and you don’t even know the flavor.”

Wednesday’s exchange concluded the second round of 12 scheduled Democratic debates, with some campaigns hoping that they did enough to shake up a race that has largely been guided by four candidates: Biden, Harris, and Sens. Bernie Sanders (I-Vt.) and Elizabeth Warren (Mass.).

Highlights from Night 2 of the second Democratic debate

If the first night was a showcase of the liberal-vs.-moderate split within the party, the second night put on display other divides and a thirst to have a nominee who represents the party’s growing diversity. Half of the 10 candidates onstage Wednesday at the Fox Theatre were minorities, making it a historically diverse lineup.

“Mr. President, this is America,” Biden said, addressing President Trump, pointing to the diversity in race and experience onstage. “And we are stronger together because of this diversity. Not in spite of it, Mr. President. We love it, we are not leaving it. We are here to stay. And we’re certainly not going to leave it to you.”

Much like the night before, the debate began with a prolonged — and at times intense — discussion about health care, with candidates sparring over whether to eliminate private insurance as part of a push to provide universal coverage.

Harris, who formerly supported Sanders’s Medicare-for-all plan — which would abolish private health insurance and put a government-run plan in its place — released a new proposal Monday that would allow private insurance as long as it followed Medicare’s coverage rules. Biden accused her of being inconsistent in her positions, and of not being forthcoming about the costs for middle-class taxpayers.

“This idea is a bunch of malarkey, what we’re talking about here,” he said. “I don’t know what math you do in New York, I don’t know what math you do in California.”

“Yeah, let’s talk about math,” Harris responded, calling Biden part of the “status quo” and citing the billions of dollars in profits going to the pharmaceutical and insurance industries. “You do nothing to hold insurance companies to task for what they’ve been doing to American families.”

But the verbal crossfire was perhaps most frenetic during a prolonged exchange about the criminal justice system.

Booker had spent the week before the debate forecasting his lines of attack, with an emphasis on Biden’s criminal justice record as a senator, which resulted in harsh penalties for offenders. Referring to Biden’s signature 1994 crime bill, and the increase in African Americans put in prison as a result, Booker called him “an architect of mass incarceration.”

In the weeks leading up to the debate, Biden released a criminal justice policy that would eliminate the death penalty and reduce punishments for some drug offenses, rolling back aspects of the laws he helped put in place.

“This is one of those instances where the house was set on fire and you claimed responsibility for those laws,” Booker said. “And you can’t just now come out with a plan to put out that fire.”

Biden defended his record while challenging Booker over his handling of the Newark Police Department while he was mayor. Biden said Booker stood by idly while the department engaged in stop-and-frisk policies that disproportionately targeted black men.

“If you want to compare records — and, frankly, I’m shocked that you do — I’m happy to do that,” Booker said.

Harris faced criticism for her record as a prosecutor, particularly from Rep. Tulsi Gabbard (Hawaii), who said Harris did not adequately use her power as an insider to protect people victimized by the criminal justice system.

“The people who suffered under your reign as prosecutor, you owe them an apology,” Gabbard said.

New York Mayor Bill de Blasio was implicitly challenged for not firing a New York police officer who killed Eric Garner, an unarmed black man, using an unauthorized chokehold in 2014. Julián Castro, who was housing secretary under Obama, and Gillibrand said the officer, Daniel Pantaleo, should have been fired even though prosecutors had not charged him. Some in the audience jumped in with chants of “Fire Pantaleo” early in the debate.

Although Democrats have uniformly criticized Trump’s immigration policies — which include family separations and mass deportation raids — they have been deeply divided over the appropriate legislative response to a surge of migration at the U.S.-Mexico border.

During the June debate, most Democratic candidates raised their hands when asked whether they would decriminalize unauthorized border crossings, an issue that has since caused a rift in the party.

Castro targeted Biden, who does not favor decriminalizing the crossings.

The former vice president also said he and Castro had sat together in many Cabinet meetings.

“I never hear him talk about any of this when he was [housing and urban development] secretary,” Biden said. “The fact of the matter is, if you cross the border illegally, you should be able to be sent back. It’s a crime. It’s a crime.”

Castro replied: “It looks like one of us has learned the lessons of the past, and one of us hasn’t.” Pointing to various border-control measures, he added: “What we need is politicians that actually have some guts on this issue.”

Biden responded: “I have guts enough to say his plan doesn’t make sense.”

Several candidates pressed Biden to explain whether he opposed the Obama administration’s deportation policies, and he dodged repeatedly.

“I was vice president. I am not the president,” he said. “I keep my recommendations private.”

Booker, who has struggled to wrest away some of Biden’s support among black voters, quickly jumped in with a sharp retort.

“First of all, Mr. Vice President, you can’t have it both ways,” he said. “You invoke President Obama more than anybody in this campaign. You can’t do it when it’s convenient then dodge it when it’s not.”

Obama remains highly popular in the Democratic Party, making any internal critiques of his record politically perilous for candidates vying to become president.

“Am I the only one that misses Barack Obama in this room?” Tom Perez, the chairman of the Democratic National Committee, asked the debate audience in the lead-up to the exchange, as the crowd erupted in cheers.

But as several Democrats onstage Wednesday rushed to criticize Biden, they grew increasingly comfortable with criticizing Obama’s legacy by proxy. The Obama administration’s record on deportations, criminal justice, trade and health care was challenged implicitly and explicitly by several candidates.

Even Biden stepped away from the former president on one issue, saying he no longer supports the Trans-Pacific Partnership, a trade deal Obama backed.

The debate marked a rematch between Biden and Harris. She directly attacked him in the June forum over his willingness to work with segregationist senators, particularly on measures to restrict court-mandated busing as a way to further integrate schools. Biden was caught off guard, with advisers offering various explanations, including that he had endorsed her in her 2016 Senate race and that she had been friends with his late son, Beau Biden.

Winners and losers from the second Democratic debate

Before Wednesday’s debate, Biden’s campaign aides insisted that he was ready for the onslaught of attacks, and that he had learned from the first debate in Miami that his record would come under deeper and more personal scrutiny than he had anticipated.

“Go easy on me, kid,” Biden told Harris as she came onstage and shook his hand. She smiled and said, “You good?”

Biden faced a barrage of direct challenges for his record on gender equality and abortion rights, with Gillibrand and Harris leading the charge.

Gillibrand questioned Biden repeatedly about past comments in which he suggested that outsourcing child care was not good for families. She characterized his quotes as being opposed to women working outside the home.

Biden pushed back on the senator from New York, saying that she had previously praised his record on women’s issues and indicating that her attack was politically motivated.

“You came to Syracuse University with me and said it was wonderful I’m passionate about . . . making sure women are treated equally,” he said. “I don’t know what’s happened except that you’re now running for president. So I understand.”

The discussion ended when Biden said he has never thought that women who work outside the home were shirking their responsibilities or hurting their families.

But there was no letup, as Harris immediately jumped in and trained her fire on Biden for his support of the Hyde Amendment, which restricts federal funding for abortion. Last month on the campaign trail, Biden reaffirmed his support for the measure before saying the next day that he would abolish it.

“Why did it take you so long to change your position on the Hyde Amendment?” Harris asked.

More than half of the candidates in the field are at risk of not meeting the polling and donor thresholds to qualify for the next round of debates in September. The first night of the second debate attracted only about half the television audience as the first night of the June debate.

Trump weighed in before Wednesday’s exchange with his views about the first night of the debate, tweeting: “Very low ratings for the Democratic Debate last night — they’re desperate for Trump.”

The contentious and rowdy tone of the debate at times forced Democrats to concede that the president and Republicans might ultimately benefit from their internal squabbles.

“The person that’s enjoying this debate most right now is Donald Trump, as we pit Democrats against each other, while he is working right now to take away Americans’ health care,” Booker said.

Tim Murtaugh, the Trump campaign’s communications director, clipped part of Booker’s quote and endorsed the idea that Trump was enjoying the Democrats’ dust-up.

“Fact Check: TRUE,” he tweeted.

Trump was referenced several times during the debate, with Gillibrand saying the first thing she would do as president is “Clorox the Oval Office” and Andrew Yang, an entrepreneur, saying he was building a coalition of “disaffected Trump voters.”

“For the last three years, we’ve been consumed by a president who, frankly, doesn’t give a damn about your kids or mine,” said Sen. Michael F. Bennet (Colo.). “Mr. President, kids belong in classrooms, not cages. And they deserve something better than a bully in a White House. Let’s end this three-ring circus in Washington.”