MIAMI — A former career U.S. diplomat told a federal judge Thursday he will plead guilty to charges of working for decades as a secret agent for communist Cuba, an unexpectedly swift resolution to a case prosecutors called one of the most brazen betrayals in the history of the U.S. foreign service.

Manuel Rocha’s stunning fall from grace could culminate in a lengthy prison term after the 73-year-old said he would admit to federal counts of conspiring to act as an agent of a foreign government.

His post-government career included time as a special adviser to the commander of the U.S. Southern Command and more recently as a tough-talking Donald Trump supporter and Cuba hardliner, a persona friends and prosecutors say Rocha adopted to hide his true allegiances.