Haroon Ullah has advised two secretaries of state on fighting Islamist extremism; he has degrees from Harvard University and the University of Michigan; he has written five books.

Last week he became a felon. The illustrious policy leaders who wrote blurbs for his books now were writing about why he shouldn’t go to prison for fraud.

Judge T.S. Ellis III told him that it didn’t matter that he had doctorates in philosophy and public policy — in court he would be called “Mr. Ullah,” not “Dr.” He would get three months behind bars, more than prosecutors requested.

Over a nine-month period last year, the 41-year-old counterterrorism expert and chief strategy officer at the U.S. Agency for Global Media (USAGM) gambled his career on a handful of flight upgrades, free trips and a bit of cash — and lost spectacularly. For what amounted to $34,000 in falsified expense accounts, he lost a $160,000-a-year job with the Senior Executive Service, along with much hope of future employment in government.

Ellis rejected an agreement to recommend two months in jail, which Ullah had hoped to serve on weekends. The judge said he was “surprised” the prosecutors he usually considers too harsh were so lenient.

“You steal this much money from the government, there has to be a significant consequence,” ­Ellis said in federal court in Alexandria.

In court, Ullah struggled to explain his actions, calling the crime in retrospect a “surreal . . . out-of-body experience.” He inflated Uber trips and made up hotel stays; he billed the government when traveling to visit family or promote his most recent book. He forged a doctor’s note claiming that he needed to fly first class because of knee pain. He also lied to his insurance company about tree damage on his Alexandria home, although his lawyers say that fraud cost the firm no extra money.

Along with his job, Ullah lost two close friends, a doctor and a real estate agent, by implicating them in fraud.

“I devoted my career to promoting American values,” Ullah said. “I lost my way; I lost my moral compass.”

Ullah worked at the State Department starting in 2010, before leaving for the USAGM, which oversees government-backed international news publications. The agency was rocked by a scandal last year over anti-Semitic programs aired in Cuba. Ullah came to the job with a background studying Islamist politics in Pakistan and Afghanistan, and working in Islamabad for the State Department.

Defense attorney Mark Schamel suggested that close calls during terrorist attacks in that posting along with personal tragedies helped explain Ullah’s conduct. Prosecutors disagreed.

“Post-traumatic stress may explain . . . impulsive actions that harm self or others,” Assistant U.S. Attorney Russell Carlberg wrote. “But it is difficult to see how it leads a senior official with substantial intellectual capacity, painstakingly to create multiple types of fraudulent documents; practice forged signatures; and then to profit off the money received as a result of his deception.”

Ellis agreed, saying the fraud went on for too long and was performed too “imaginatively.” He noted that Ullah’s net gains would have been closer to $50,000 had some expenses not been rejected.

“If you had done it once, it would be an aberration and you wouldn’t be here,” he said.

In June, Ullah pleaded guilty to theft of government property.

According to people familiar with the case, a USAGM staffer first reported concerns about the amount of time and money Ullah spent traveling to superiors in August 2018. Ullah became belligerent in response, leading to a complaint of a hostile workplace, according to those people; management initially agreed with him that nothing was wrong with the trips.

But a travel specialist at the agency began scrutinizing Ullah more closely, calling two hotels in New York where he claimed to have stayed in September, according to court records. Neither had any record of his visit and said the invoices were not theirs.

The agency then started calling other hotels where Ullah claimed to have stayed, found more discrepancies, and called in the Office of the Inspector General, according to court documents. Investigators learned that he had fabricated dozens of hotel invoices, as well as forging letters from a doctor friend to justify flying first class. He was immediately suspended, and fired not long after.

“This is a sophisticated fraudster who was in a senior position using very sophisticated tactics,” USAGM general counsel David Kliberman said.

Some former colleagues questioned why his foreign business-class travel did not raise immediate flags. But in court, Ullah marshaled high-profile support.

Eileen O’Connor, a former war correspondent and State Department official who worked with Ullah in Afghanistan and Pakistan, wrote that he “is too important an asset for this country’s national security apparatus to lose completely.”

Retired Marine Gen. John Allen wrote a letter trying to persuade prosecutors not to charge Ullah at all; it was ultimately used in his plea for a lighter sentence.

“Under normal circumstances, it certainly makes sense to apply the traditional reprimand and penalties to Haroon,” he wrote. But, he said, “I wholeheartedly believe that Haroon’s unique skill set in fighting counterterrorism and protecting this country at the highest levels is of critical importance to our country’s . . . future national security needs.”

Left unmentioned in the letter is that Allen knows well how it feels to lose a career in public service over an indiscretion. Although he was ultimately cleared of wrongdoing, he retired in 2013 as commander of U.S. and NATO forces in Afghanistan over flirtatious emails he sent a Tampa socialite.

“This is a very impressive set of letters,” Ellis said. But he said too many lacked “any awareness that he stole money.”

Along with his jail sentence, the judge ordered Ullah to perform 30 hours of community service — specifically, telling high-level government officials: “Don’t falsify documents for your expenses. It’s a crime.”