The only public explanation former vice president Joe Biden has given for why he was so unprepared for Sen. Kamala D. Harris’s attack in the first Democratic debate boils down to this: He did not expect something like that from the candidate who had been so close to his late son.

“I was prepared for them to come after me, but I wasn’t prepared for the person coming at me the way she came at me,” Biden told CNN. “She knew Beau. She knows me.”

Harris’s close friendship with Beau Biden, who died of brain cancer in 2015 at age 46, is giving an unusually personal tone to the growing rivalry between Biden and Harris (D-Calif.), which will be on display again at Wednesday’s debate.

Harris and the younger Biden developed a bond in the early 2010s as fellow state attorneys general in California and Delaware, respectively, strategizing on cases and comparing notes as politically ambitious future Democratic stars.

That fostered a connection between Harris and the elder Biden. He endorsed her 2016 U.S. Senate run, and some Democrats saw the pair as a dream 2020 ticket. But now some in Biden’s camp consider Harris’s surprise attack, and her ongoing critique of his civil rights record, a personal breach.

“I don’t pretend to know what’s in the vice president’s head — I wasn’t surprised that someone came after him,” said a longtime friend of Beau’s, who spoke on the condition of anonymity because of the sensitivity of the subject. “But I turned to my wife and said, ‘Beau’s flipping in his grave.’ ”

Harris’s attack on Biden turbocharged her candidacy and raised questions about Biden’s strength as a candidate. But the wrenching moment has redefined their relationship and created an emotion-tinged rivalry that could simmer in the months ahead.

Speaking Thursday on the “Tom Joyner Morning Show,” which has a large African American audience, Biden said of Harris, “I thought we were friends. I hope we still will be.”

Not everyone accepts Biden’s suggestion that it was a betrayal for an intimate of Beau’s to challenge onstage his opposition to busing and his work with segregationist senators. When Harris appeared recently on “The Breakfast Club,” another radio show influential among African Americans, host DJ Envy said he thought Biden was “looking for sympathy.”

Harris made clear that she had no original allegiance to Joe Biden — she pointed out she had supported Barack Obama, not Biden, for president in 2008 — and that her loyalty was to Beau, about whom she was effusive.

“He was an incredible person, an incredible human being and a very dear friend to me,” Harris said on the show. She added pointedly, “That’s separate from the fact that segregationists in the United States Senate stood, and lived their careers, to segregate the races in public education in the United States.”

The coming debate will show what lessons Harris and Biden took from their clash in their first faceoff. The first night, July 30, includes Sens. Elizabeth Warren (D-Mass.) and Bernie Sanders (I-Vt.), the most prominent liberal candidates. The following evening will feature a rematch of sorts between Harris and Biden.

At a fundraiser in Detroit on Wednesday, Biden suggested that if Harris comes after him, he will hit back.

“I’m not going to be as polite this time, because this is the same person who asked me to come to California and nominate her in her convention,” he said.

Biden spoke on behalf of Harris’s Senate run at the 2016 California Democratic convention.

When Biden brings up his son on the campaign trail, it is often a way to reach out to voters who have suffered their own difficult losses or to empathize with parents who have sent children to war, as the former vice president did when Beau served in Iraq.

Before he was diagnosed with brain cancer, Beau Biden seemed destined for his father’s Senate seat, or perhaps the Delaware governor’s mansion. He was a rising star at around the same time Harris’s political ascent began in California, and they both served as state attorneys general from 2010 to 2014.

Despite representing states on opposite coasts — one large, one tiny — Harris and Biden found common ground on issues such as elder abuse, child abuse and, most memorably, a high-stakes negotiation with five big banks in the wake of the foreclosure crisis.

As a settlement with the banks was emerging, Harris refused to sign on, arguing that the financial terms were too easy on the banks. Beau Biden agreed, and he joined Harris — along with Attorneys General Martha Coakley of Massachusetts and Catherine Cortez Masto, now in the U.S. Senate representing Nevada — as high-profile holdouts to the proposed deal.

The four faced intense pressure from constituents, banks and even the Obama administration, a crucible that created a personal and professional bond.

In her book, “The Truths We Hold: An American Journey,” Harris wrote that there were times when “Beau and I talked every day, sometimes multiple times a day.” On other occasions, Harris and her team would fly to Washington to meet with Biden and his assistants.

By the time Beau Biden died on May 30, 2015, at Walter Reed National Military Medical Center in Bethesda, Md., his closest staffers had compiled a list of roughly 60 people they thought should know about his passing first. Harris was on that list.

She attended the funeral and has continued to make personal statements about how she misses him. Harris offered her condolences on Twitter after Beau’s death four years ago, and again on the anniversary of his death earlier this year.

“Beau Biden was my friend. We were AGs together, and you couldn’t find a person who cared more deeply for his family, the nation he served, and the state of Delaware,” Harris wrote two months ago, with a photo of her and Beau Biden smiling together. “Four years after his passing, I still miss him.”

The photo was from 2013, when Beau was on a trip to San Francisco. His staff had scheduled the visit to help him build a broader political network.

Beau Biden told his aides not to schedule anything without first calling Harris, who had served two terms as San Francisco district attorney. The Bay Area was her political turf, and he did not want to intrude on that terrain if he would be unwelcome.

Besides, recounted a longtime friend of Beau’s, he trusted Harris’s opinion on whom to meet with when he was on the West Coast and whom to avoid.

As it happened, the two ended up hosting a joint luncheon that an aide recalled was held at McKinsey & Company, a prominent consulting firm, while he was in the Bay Area. The photo was taken afterward.

Harris’s friendship with Beau Biden ultimately led to a warm political relationship with his father. When Biden, as vice president, endorsed Harris’s 2016 Senate campaign, she posted his statement on her campaign website.

“Beau always supported her,” Biden wrote, “and I’m proud to support her candidacy for the United States Senate.”

In the intervening years, Harris often praised the elder Biden. She once tweeted that he was “a good man with a big heart” and that he “worked tirelessly throughout his career to improve the lives of millions.” As recently as March, Harris said, “You’re not going to hear me criticize Joe Biden. I think he’s a great guy.”

That goodwill led some Democrats to wonder whether Biden and Harris might share the 2020 Democratic ticket. In May, a reporter asked Harris whether she would consider being Biden’s running mate. She responded with a quip suggesting she would have to be the one in charge.

“I think that Joe Biden would be a great running mate,” Harris said. “As vice president, he’s proven that he knows how to do the job.”

That tone of gentle ribbing changed dramatically at the first Democratic debate in June. It was a moment when Harris was looking to give her campaign a boost and Biden was comfortably atop the polls. Once onstage, she confronted him on racial issues in highly personal terms, suggesting he was off-base in the way he talked about an issue fundamental to millions of Americans.

The way Biden had described working with segregationist senators, Harris said, was “hurtful.” She attacked him for supporting antibusing legislation in the 1970s, noting that she had been bused to school as a girl.

“I will tell you that on this subject, it cannot be an intellectual debate among Democrats,” she said. “We have to take it seriously. We have to act swiftly.”

Their staffs then brawled for hours on Twitter about the candidates’ respective positions and records. An unnamed Biden adviser was quoted in Politico calling Harris “slick and slippery.” A few days later, Biden was forced to apologize for the way he had spoken about his working relationship with segregationist senators.

Since then, Biden has ridiculed Harris, indirectly at least, on issues such as how she would fund her health plan, while Harris has not backed away from her suggestion that Biden has been racially insensitive. Their conflict has become part of the story of the campaign, as Harris seeks to become the main alternative to Biden within the party, a younger figure who is more in touch with the times.

On Wednesday, when they share the stage again, Democrats will be watching to see whether they revive their attacks or take a more conciliatory tone. Both may have to stave off assaults from less-prominent candidates.

Their first confrontation catapulted Harris in the national polls, closing the gap between her and Biden and changing the dynamic of the race. This time, he has more warning.

“I have no intention of attacking Joe Biden,” Harris said when asked about him on ABC’s “The View” earlier this month. “I am going to point out our differences of opinion on a very critical moment in the history of the United States.”

Beau Biden, she argues, has nothing to do with that.