The U.S. Secret Service is in the business of protecting the president, whether he’s inside the Oval Office or visiting a foreign war zone.

But protecting a former president in prison? The prospect is unprecedented. That would be the challenge if Donald J. Trump — whom the agency is required by law to protect around the clock — is convicted at his criminal trial in Manhattan and sentenced to serve time.

Even before the trial’s opening statements, the Secret Service was in some measure planning for the extraordinary possibility of a former president behind bars. Prosecutors had asked the judge in the case to remind Mr. Trump that attacks on witnesses and jurors could land him in jail even before a verdict is rendered.

(The judge, who is holding a hearing Tuesday to discuss whether Mr. Trump should be held in contempt for violating a gag order, is far more likely to issue a warning or impose a fine before taking the extreme step of jailing the 77-year-old former president.)

Last week, as a result of the prosecution’s request, officials with federal, state and city agencies had an impromptu meeting about how to handle the situation, according to two people with knowledge of the matter.

That behind-the-scenes conversation — involving officials from the Secret Service and other relevant law enforcement agencies — focused only on how to move and protect Mr. Trump if the judge were to order him briefly jailed for contempt in a courthouse holding cell, the people said.