It happened routinely during Roger Clemens’s long and legendary baseball career: The pitcher won a game and then autographed baseballs for fans, who left the ballpark with smiling faces.

What a difference a change of setting can make.

Not long after the judge overseeing Clemens’s perjury trial in the District’s federal court declared a mistrial in July, several courthouse security officers received baseballs signed by Clemens.

It’s not entirely clear who sent them, why they were sent or whether anyone at the courthouse expected them — just that someone associated with Clemens’s defense team gave a half-dozen balls to a guard, who handed them out. On Tuesday, the U.S. Marshals Service confirmed an investigation into the matter, in which as many as six guards received balls.

There is no indication that Clemens or his attorneys face penalties in connection with the signed balls. But the guards, whose identities have not been disclosed, could face dismissal or other penalties, according to sources familiar with the probe.

The guards, who work for a private security firm, are not allowed to accept gifts from defendants. Baseballs signed by Clemens fetch between $100 and $400 at online retail sites, depending on their condition and the circumstances of the autograph.

The Marshals Service said it asked the security firm to investigate the matter last week in response to a reporter’s questions about the balls. That company, California-based Inter-Con Security Systems, will report on its findings, after which the Marshals Service will decide whether to take further action.

A Marshals Service spokeswoman, Lynzey Donahue, declined to discuss specifics of the case but said in a statement that a preliminary investigation revealed that “up to six baseballs were given to a contracted court security officer and were distributed among four or five other court security officers.”

Donahue said a “preliminary inquiry indicates that no U.S. Marshals personnel received any memorabilia from the Roger Clemens defense team.”

Lance Mueller, chief operating officer of Inter-Con Security, said the “investigation is active, and we hope to wrap it up soon.” Inter-Con has a contract worth $5.2 million a year to provide security at the courthouse in the 300 block of Constitution Avenue NW.

Clemens’s lead attorney, Rusty Hardin, declined to comment on the matter last week, and he did not respond to e-mails seeking comment Tuesday.

His client, baseball’s most decorated pitcher, did not appear to receive any special treatment from the security officers during his abbreviated perjury trial, which started early last month.

Clemens entered the courthouse as anyone else would, ate in the cafeteria and left by public entrances. For security reasons and to prevent the disruption of other courthouse business, the guards helped shepherd Clemens past a battalion of reporters and photographers as he left the courthouse after the mistrial was declared July 14.

The balls, which arrived at some point after Clemens left the courthouse, might have been a thank-you gift from the defense team for such help, according to sources familiar with the investigation.

Outside legal experts said sending balls to the guards was not a smart move but is unlikely to result in sanctions against Hardin or his team. The guards are also unlikely to face criminal charges, legal experts said.

A hearing to decide whether Clemens can be retried has been set for Sept. 2.

“It would have been more prudent to wait to send the balls until the case was completely over,” said Steven Levin, a criminal defense lawyer and former federal prosecutor. “I don’t know what the rush was to do it. . . . The court might view it as a exercise of poor judgment. But I don’t think anyone would view this as a criminal conduct.”

Clemens is charged with lying to Congress in 2008 when he denied having taken performance-enhancing drugs. The high-profile perjury trial came unglued two days into testimony when federal prosecutors blundered and presented barred evidence to the jury. U.S. District Judge Reggie B. Walton declared a mistrial and is weighing legal arguments about whether federal prosecutors should get another crack at the 11-time all-star.

The mistrial was an embarrassment for the Justice Department, and the prosecutorial error clearly irked Walton. Whether Clemens’s attorneys end up in foul territory with the judge remains to be seen.