Updated 3 p.m. with Ribeiro comment

Mayor Vincent C. Gray will serve the last 51/2 months of his term without his most stalwart public defender, chief spokesman Pedro Ribeiro.

Ribeiro, Gray’s communications director since late 2011, is leaving for a senior post in the Department of Homeland Security next month, according to an e-mail sent to administration officials Tuesday. He joins several high-ranking Gray deputies to plan their exits in the wake of the mayor’s April 1 primary loss. WUSA (Channel 9) reporter Bruce Johnson first tweeted news of Ribeiro’s departure Tuesday morning.

“The Mayor and I are grateful to Pedro for his nearly three years of service to the Gray Administration and to the District,” Gray Chief of Staff Christopher Murphy said in the e-mail. “Pedro has been a trusted and valued advisor and counselor to the Mayor and his entire senior team as well as an effective spokesperson who managed to disagree with the press when he had to without being disagreeable. We are sorry to see him go.”

Ribeiro on Tuesday declined to discuss details of his new position. “There will be time in the future to talk about that,” he said. “It’s just been an honor to serve.”

Doxie McCoy, formerly communications director to Del. Eleanor Holmes Norton (D-D.C.) before joining the Gray administration, will take over for Ribeiro, according to the e-mail.

The 37-year-old Columbia Heights resident, came to the Gray administration as a part of an executive-office overhaul in the wake of several early controversies that knocked his tenure adrift. Along with Murphy and Deputy Chief of Staff Sheila Bunn, Ribeiro helped Gray find new political footing after months of bad headlines prompted by the early hiring of the children of political insiders and the quid pro quo allegations of fellow 2010 mayoral candidate Sulaimon Brown.

When the allegations of campaign wrongdoing escalated in 2012, with revelations of a secret “shadow campaign” on Gray’s behalf in 2010, Ribeiro labored to keep attention focused on Gray’s governing initiatives. That often involved interacting aggressively with reporters — for instance, snapping at a Washington City Paper reporter after asking a skeptical question about Gray’s economic development record at a news conference last year — and sometimes vividly mocking Gray’s political rivals on the D.C. Council and elsewhere.

When Tommy Wells (D-Ward 6) questioned the management of the city’s fire department in a public letter, Ribeiro called it a “shameless and idiotic stunt.” When David A. Catania (I-At Large) took aim at a settlement with the firm owned by admitted shadow campaign financier Jeffrey Thompson, Ribeiro called Catania “either a fool or a liar.” And when Virginia state Sen. Richard Saslaw (D-Fairfax) questioned the trustworthiness of city politicians, Ribeiro quickly noted that the state’s own former governor had ethics issues of his own.

Raised in Northern California by Portuguese immigrant parents, Ribeiro was previously a communications aide to two Democratic members of Congress, Rep. Zoe Lofgren (Calif.) and Henry Cuellar (Texas).

With the council easily overriding his veto of its 2015 budget plan Monday, Gray’s political clout is at low ebb and only stands to recede further as his single term winds to a close. But Gray has said he intends to keep pursuing key initiatives, including a $300 million pro soccer stadium financing deal.