Detroit (CNN) Joe Biden entered the second Democratic debat e on Wednesday night facing serious doubts about whether he could take the fight to President Donald Trump. He survived to fight on for the Democratic nomination, delivering a far steadier performance than in the first debate but he spent most of the night fending off attacks from nearly every one of his rivals.

The volley of attacks on Biden in Detroit began when California Sen. Kamala Harris opened the debate with a sharp critique of the former vice president's health care plan as one that lacked ambition and fell far short of addressing the rising health care costs that many Americans are facing.

It continued with New Jersey Sen. Cory Booker suggesting that Biden was one of the chief architects of a criminal justice system that disproportionately incarcerated black and brown men. Former Housing and Urban Development Secretary Julián Castro soon entered the fray by accusing the former vice president of failing to learn from the Obama administration's mistakes on immigration.

New York Sen. Kirsten Gillibrand rounded out the debate by falsely twisting Biden's words from a 1981 op-ed opposing an amendment on a childcare tax credit to make it sound as though he had suggested that women working outside the home would lead to the deterioration of the nuclear family.

Through it all, Biden shook his head and smiled, at several points deflecting with wit and humor. In one of those moments -- after New York Mayor Bill de Blasio asked if Biden would admit that labor should have been more engaged in negotiating trade agreements like NAFTA -- Biden replied with a simple "Yes."

"I consider that a victory," de Blasio said.

"Well, I love your affection for me. You spend a lot of time on me," Biden returned.

"We believe in redemption in this party," De Blasio said.

"I tell you what, I hope you're part of it," Biden quipped.

When Gillibrand made the baseless claim that Biden had been unsupportive of working women in the 1980s -- which led him to note that both his deceased first wife and his current wife worked outside the home -- Biden reminded the New York senator that she had sought his help on initiatives to protect women and that they'd traveled to Syracuse University together, where she'd described his work as wonderful.

"I don't know what happened except you're running for president," Biden said.

In the surprise performance of the night, Booker delivered one of the most forceful denunciations of Biden's record. The New Jersey senator managed to thread the needle between pushing his campaign message of unity and love to restore hope in America, while landing some effective punches on Biden's record on criminal justice.

Booker noted that the former vice president bragged until recently about his work on 1994 crime bill. He also charged that Biden had been on the wrong side of many issues, including tougher sentencing laws that led to a disproportionate number of black and brown Americans being incarcerated.

"The house was set on fire and you claimed responsibility for that fire," Booker said to Biden about his record criminal justice reform.

In a surprising twist, Biden turned on Booker by challenging his record in Newark.

"There was nothing done to deal with" a police department "that was corrupt," Biden said of Booker's record as mayor of Newark.

Booker appeared to relish the exchange, saying, "If you want to compare records, and I'm shocked that you do, I am happy to do that." He added that Biden didn't know what he was talking about.

"There's a saying in my community that you're dipping into the Kool-Aid and you don't even know the flavor. You need to come to the city and see the reforms we put in place," Booker said.

Biden used the exchange with Booker to remind the audience that Barack Obama picked him as his vice president.

"I find it fascinating, everybody is talking about how terrible I am on these issues," Biden said. "Barack Obama knew exactly who I was. He had 10 lawyers do a background check and everything about me on civil rights and he chose me and said it was the best decision he ever made."

Booker had an answer for that too.

"You invoke President Obama more than anybody in this campaign. You can't do it when it's convenient and dodge it when it's not," he said.

Biden forced to defend Obama on deportations

When the debate shifted to immigration, it was Castro who criticized Biden's record during the Obama administration, and sought to turn it into an argument that it is time for new leadership.

One of CNN's moderators had noted that 800,000 immigrants were deported during the first two years of the Obama administration, and asked the former vice president whether those deportations would continue if he was president. Biden said they would not.

The former vice president noted that he and Castro had been in many meetings together, and said Castro never pushed his current stance in favor of decriminalizing border crossings.

"We sat together in many meetings, I never heard him talk about any of this when he was the secretary," Biden said.

"It looks like one of us has learned from the lessons of the past and one of us hasn't," Castro snapped back. "We need to have some guts on this issue."

Biden defended his record noting that had pushed to send $750 million for Guatemala, El Salvador and Honduras so that people there could "change the circumstance" of "why people fled in the first place."

"We're in a circumstance where if you say you can just cross the border, what do you say to all of those people around the world who want the want the same thing to come to the United States and make the case, that they have to wait in line," 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."

Calling for unity, Booker made a forceful argument for immigration offenses to be civil penalties instead of criminal penalties.

"We are playing into Republican hands who have a very different view and are trying to divide us against each other. I'm listening to the language of my colleagues," Booker said. "No, Mr. Vice President, we are not going to let people cross the border."

A few moments later, de Blasio used his time to ask Biden to explain what he had done to stop the deportations during the time that he was Obama's vice president.

"I asked the vice president if he used his power to stop those deportations," de Blasio asked. "If you want to be President of the United States, you need to be able to answer the tough questions. I guarantee you, if you're debating Donald Trump, he's not going to let you off the hook. Did you say those deportations were a good idea or did you go to the President and say, 'This is a mistake, we shouldn't do it.' Which one?"

It was the question Biden wouldn't answer, citing his private conversations with Obama -- which led Booker to argue that Biden couldn't have it both ways.

The stage showed off the diversity of the Democratic field and also the generational differences among the candidates. Harris and Booker, for example, have argued for a new generation of leaders who better reflect the diversity of the Democratic Party. Also on the stage on Wednesday were Colorado Sen. Michael Bennet, Washington Gov. Jay Inslee and businessman Andrew Yang.

Hawaii Rep. Tulsi Gabbard also had a strong night, delivering a sharp attack on Harris' record as California's attorney general and highlighting her own record as the only veteran on the stage. Biden faulted Harris for defending cases that were found to have involved prosecutorial misconduct, and for not disclosing more quickly to defense attorneys that evidence in the San Francisco crime lab had been tampered with.

"She had a police department when she was there that in fact was abusing people's rights and the fact was that she, in fact, was told by her own people -- by her own staff -- that she should do something about and disclose to defense attorneys like me," Biden said, "that you in fact have been -- the police officer did something that did not give you information that would help your client. She didn't do that."

Gabbard delved further into the more controversial aspects of Harris' record as a prosecutor.

"She blocked evidence that would have freed an innocent man from death row," Gabbard said. "She kept people in prison beyond their sentences to use them as cheap labor for the state of California, and she fought to keep cash bail system in place that impacts poor people in the worst kind of way."

Harris deflected by saying that the attacks on her record were inaccurate. During a post-debate interview with CNN, she said she had difficulty taking Gabbard's comments seriously since she had "been an apologist for" the Syrian leader Bashar Assad.

Fiery debate over the future of health insurance

While the ideological divide was less marked than it was during the first debate in Detroit that centered on plans proposed by Massachusetts Sen. Elizabeth Warren and Vermont Sen. Bernie Sanders, Harris and Biden vigorously sparred over the differences in their health care plans.

While Biden would expand Obamacare with the goal of universal coverage but not force Americans to give up their private health insurance, Harris' plan would phase in "Medicare for All" and phase out private insurance over 10 years. Biden faulted Harris for shifting her position several times this year.

"The senator has had several plans so far, and anytime someone tells you you're going to get something good in 10 years, you should wonder why it takes 10 years," Biden said, alluding to Harris' plan. "If you notice, there is no talk that the plan in 10 years will cost $3 trillion."

Harris replied that Biden's description of her plan was "simply inaccurate."

"The reality is our plan will bring health care to all Americans under a Medicare for All system," the California senator said. "Our plan will allow people to start signing up on the first day, babies will be born into our plan and right now 4 million babies, almost, are born every day -- or every year in America. Under our plan we will ensure everyone has access to health care. Your plan, by contrast, leaves out almost 10 million Americans."

Over and over again -- even when responding to criticism from Gabbard -- Harris returned to criticize Biden's plan.

"I'm going to go back to Vice President Biden," she said when given the opportunity to respond to Gabbard, "because your plan does not cover everyone in America by your staff's and your own definition ... as many as 10 million people will not have access to health care, and in 2019 in America."

After another contentious exchange it was Yang who sought to remind his rivals of their real opponent.

"I speak for just about anyone watching that I would trust anyone on this stage more than I trust our President. We have to focus on beating Donald Trump in 2020," he said.

This story has been updated.