For more than seven hours Wednesday, Michael Cohen unspooled a withering portrait of President Trump, painting his longtime patron as a liar and a fraud in starkly personal terms.

He described how Trump ordered him to lie to the first lady about his relationship with an adult-film star and personally directed a hush-money scheme. He said Trump inflated his net worth to try to secure loans and to boost his status. He recounted how Trump made racist remarks, claiming he said at one point that African Americans were “too stupid” to vote for him.

It was a stunning turn for a man who served as Trump’s lawyer and all-purpose fixer for more than a decade, a role he once embraced with unapologetic ferocity pledging to take a bullet on the mogul’s behalf as evidence of his loyalty.

On Wednesday, he was equally zealous about the president’s failings. During occasionally emotional testimony before the House Oversight Committee, Cohen used his backstage view of Trump to level a broad attack against the president’s character.

“Since taking office, he has become the worst version of himself,” Cohen said. “He is capable of behaving kindly, but he is not kind. He is capable of committing acts of generosity, but he is not generous. He is capable of being loyal, but he is fundamentally disloyal.”

Cohen’s depiction of himself as a credible witness was complicated by his own admitted criminal conduct and past lies — including false statements he made previously to Congress.

Altogether, he has pleaded guilty to nine felonies, including tax evasion and campaign finance violations. In May, he is scheduled to begin serving a three-year prison sentence, the culmination of his dramatic fall from Trump intimate to outcast and felon.

Throughout the day, Republicans members of the Oversight panel repeatedly used Cohen’s lies to disparage him and challenge his veracity.

“Certainly it’s the first time a convicted perjurer has been brought back to be a star witness in a hearing,” Rep. Jim Jordan (R-Ohio) told Cohen, deriding him as a “cheat” and a “fraudster” who is about to go to prison. Referring to the Democrats, Jordan said, “They just want to use you, Mr. Cohen. You’re their patsy today, Mr. Cohen.”

Cohen largely absorbed the assault without dissent, casting himself as a cautionary tale for other Trump allies.

Asked during his testimony if White House staffers may end up in legal jeopardy because of their allegiance to the president, he replied, “Sadly, if they follow blindly like I have, the answer is yes.”

Cohen described a widespread culture of lying around Trump, as he sought to explain why he stayed by the president’s side for so long.

He described how their schemes evolved from “trivial” to “significant and dangerous” as Trump graduated from private businessman and television celebrity to the Republican presidential nominee.

He portrayed himself as an unquestioning member of a cultlike following, saying he carried out the president’s orders “and concealed his illicit acts” without hesi­ta­tion because “I was so mesmerized by Donald Trump that I was willing to do things for him that I knew were absolutely wrong.”

“Being around Mr. Trump was intoxicating,” Cohen said. “When you were in his presence, you felt like you were involved in something greater than yourself — that you were somehow changing the world.”

Throughout the day, he offered an insider’s unvarnished view of Trump, a perspective rarely seen by the public.

“He doesn’t give you orders; he speaks in code,” Cohen testified, seated alone at the witness table, his New York roots audible in his husky voice. “And I understand the code because I’ve been around him for a decade.”

He claimed Trump “frequently told me that his son Don Jr. had the worst judgment of anyone in the world.”

Branding the president a “racist,” Cohen recalled that Trump told him that “only black people would live that way” as they drove through a poor Chicago neighborhood.

After slashing his own employees’ salaries “in half — including mine” in 2008, Cohen said that Trump boasted about the $10 million tax refund he received from the Internal Revenue Service “and said that he could not believe how stupid the government was for giving ‘someone like him’ that much money back.”

At another point, as reporters were asking about Trump obtaining a medical deferment to avoid military service in Vietnam, Cohen said Trump told him, “You think I’m stupid? I wasn’t going to Vietnam.’ ”

As for Trump’s view of his chances as the 2016 presidential campaign unfolded, Cohen said, “He never expected to win the primary. He never expected to win the general election. The campaign — for him — was a marketing opportunity.”

“Donald Trump is a man who ran for office to make his brand great, not to make our country great,” Cohen testified. “Mr. Trump would often say this campaign was going to be the ‘greatest infomercial in political history.’”

Cohen spent more than a decade championing his boss’s brand and threatening potential foes that he would “come at you, grab you by the neck, and I’m not going to let you go.”

Like Trump, who is from Queens, Cohen grew up on the edge of New York City, on Long Island, thirsting to conquer Manhattan, the epicenter of wealth, power and glamour. Before meeting Trump, Cohen became rich as a personal injury lawyer and various investments, including the taxi business.

Cohen also invested in New York City real estate, paying millions for apartments in Trump properties, including Trump World Tower, where the developer, at the suggestion of Donald Trump Jr., drafted Cohen to beat back a 2006 revolt by the building’s co-op board.

The following year, Trump hired Cohen as his counsel.

While trumpeting his boss’s various projects, whether a proposed golf course in California or a possible 2012 presidential run, Cohen also found opportunities to promote his own ambitions.

While helping to coordinate Trump’s flirtation with a 2014 New York gubernatorial campaign, Cohen told Republican strategists he wanted to run for mayor. At one point, Cohen openly floated the idea of running on a statewide ticket as Trump’s pick for lieutenant governor.

The specter of Cohen talking up his own political aspirations while supposedly working on behalf of Trump rankled the billionaire’s political advisers, some of whom said they began to question whether the attorney was as selfless as he proclaimed.

Yet in his public statements, Cohen’s fealty to his boss never wavered — that is, until July, several months after the FBI raided his residence and his office, when he declared that his “first loyalty” was to his family and country.

“Over the past year or so, I have done some real soul-searching,” Cohen told the committee Wednesday in his opening remarks. “For those who question my motives for being here today, I understand. I have lied, but I am not a liar. I have done bad things, but I am not a bad man. I have fixed things, but I am no longer your ‘fixer,’ Mr. Trump.”

More than seven hours later, his eyes tired and face drawn, Cohen issued a last warning “to those who support the president and his rhetoric as I once did.”

“I pray the country doesn’t make the same mistakes that I have made,” he said, “or pay the heavy price that my family and I are paying.”