Former Virginia governor Robert F. McDonnell declared Friday that he does not blame his wife for the federal corruption charges they face — but instead holds himself responsible for allowing a wheeling-and­-dealing executive to get close to his family and lavish gifts on them.

“I misjudged Jonnie Williams,” McDonnell testified. “I thought he was a true friend.”

On the 20th day of his trial — with his total time on the witness stand surpassing 12 hours — the 71st governor of Virginia maintained that he knows “in my heart” that he did nothing illegal in his dealings with Williams. McDonnell (R) said he blames the businessman “in part” for the charges against him, though he showed a flash of contrition and acceptance of personal failure.

“I hold myself accountable,” he said. “I got my life out of balance.”

The testimony capped a day in which McDonnell, under questioning from his defense attorney, addressed many of the specific acts prosecutors allege he took for Williams and his dietary-supplement company, Star Scientific.

List of gifts given to the McDonnell family from Jonnie Williams.

He repeatedly insisted that nothing the businessman gave him, his wife and children — $177,000 in loans, vacations and luxury goods, according to prosecutors — was worth tainting a lengthy career in public service. He also made clear that he felt Williams was lying about their interactions.

“I had no idea that he would come into federal court and make false statements against me to save himself,” said McDonnell, whose cross-examination by prosecutors will begin next week.

Of the former first lady, whom he had described for days as having a furtive relationship with Williams while their marriage crumbled, he said, “No, I don’t blame my wife.”

McDonnell said he first learned authorities were probing his dealings with Williams on the day in February 2013 that state police investigators interviewed the first lady. The session had been arranged by his chief of staff and the head of the state police, who said Maureen McDonnell was needed to help conclude an investigation into whether a chef had stolen food from the executive mansion.

That evening, Robert McDonnell said, he found his wife upset and anxious as she told him the investigators had asked questions about Williams’s loan and some of his gifts.

“I was darn angry,” he said. “I felt for them to misrepresent to my chief of staff and to me and to essentially ambush my wife in an interview was wrong.”

The episode appears important to the case because of what McDonnell did afterward. Three days later, he submitted a revised loan application to Pentagon Federal Credit Union that now listed — along with several other things — $120,000 in loans from Williams’s Starwood Trust. The governor is charged with lying on the application, and prosecutors argue that the modifications are evidence that he initially tried to hide the money he received from Williams.

The governor acknowledged Friday that once he learned what investigators were asking about, he sought“to make sure that everything I was doing was absolutely correct.” But he said he had been planning to review the application that weekend because of several mistakes he had previously noticed and corrected. His earlier omission, he insisted, was not intended to mislead the bank or hide his relationship with Williams.

The interview also marked the beginning of the end of the McDonnells’ relationship with Williams, which the governor made clear is now adversarial. Under questioning by defense attorney Henry “Hank” Asbill, McDonnell highlighted several instances in which his testimony stands in direct contradiction to the account Williams gave jurors.

McDonnell testified, for example, that he and Williams never discussed keeping secret a $50,000 loan the businessman gave to the then-governor’s real estate company in 2012. Williams had testified that he told the governor, when the specifics of the loan were still being discussed, that he would “just as soon keep this between us and no one know this.” He said McDonnell replied, “That’s fine.”

“There was no such discussion with Mr. Williams on the phone, at the February 29 meeting in my office,” McDonnell testified Friday. “If I had to report a loan or stock or something, I would have done it at the appropriate time.”

Another point of conflict came in McDonnell’s description of a September 2012 vacation to Cape Cod the governor and first lady took with Williams and his wife. Williams testified that he brought a consultant for the company on the trip and considered it a business expense. But McDonnell insisted that the trip, which included golfing, boating and over-the-top dinners, was a welcome respite after a busy August and a rare opportunity to relax with his wife.

“There was very little business on the trip,” he said, indicating that Williams asked for nothing from the state government during the long weekend. “I didn’t see fancy hotels or boats. I saw time.”

Repeatedly, McDonnell said he had not considered Williams’s gifts and loans inappropriate because Williams never asked for or received anything from the state government. In sometimes painstaking detail, McDonnell explained that his own role was limited — and routine — in each of the events that prosecutors say demonstrate that he was lending “official” help to Williams.

In August 2011, for example, McDonnell e-mailed the state health secretary asking him to send a deputy to a meeting with Williams and the first lady at the governor’s mansion to discuss Star Scientific. He made the request on the evening he returned from a vacation at the businessman’s home at Smith Mountain Lake, near Roanoke.

On the stand, McDonnell said he made that decision to ensure that “no commitments or decisions were made unless someone with the expertise was there.” He said neither his wife nor Williams asked him to have a health official there.

Later that month, McDonnell attended a Star Scientific event at the governor’s mansion, where Williams pitched researchers on his new dietary supplement. The governor said he had no role in planning the event, stayed for less than 45 minutes and thought that it was appropriate because the company gave out research grants.

Likewise, he said, it was neither “inappropriate nor abnormal” that his wife would add names to the guest list of a governor’s mansion event, as she did for a health-care leaders reception in February 2012. She invited 25 people recommended by Williams — Star Scientific employees and some researchers the company was trying to impress.

That same month, McDonnell sent an e-mail to a staff member asking to meet with him regarding possible studies of Star Scientific’s new supplement at public universities. The e-mail was sent six minutes after the governor sent a note to Williams discussing a loan.

On the witness stand, McDonnell said that his wife had told him that Williams was having trouble getting calls returned about the proposed studies and that he merely wanted his aide to make sure that Williams received an answer. He said the note about the loan came as he was wrapping up personal business in preparation for a trip.

“It would certainly not be accurate to say that I wanted to get this going,” he said.

But even though he insisted that he never did anything corrupt with Williams, McDonnell acknowledged that he had failed to disclose — accidentally, he said — two gifts from the businessman on state-mandated forms: golf outings and a golf bag.

“Again,” he said, “I take responsibility for that.”

Laura Vozzella and Rachel Weiner contributed to this report.