In text message after text message, FBI agents and their key informant joked about sex, booty calls, prostitutes, cigars, the Village People, the informant’s wives and an agent’s girlfriend. They even pondered who might play their roles in a movie based on their sting.

When arrests were announced by the Justice Department, the agents and informant basked in positive press. “It’s like an atomic mushroom cloud,” the informant gloated in a text to his FBI handler.

Since reaching court, however, there hasn’t been much to brag about in the Justice Department’s largest investigation of individuals accused of bribing foreign officials. In two lengthy and high-profile trials in the District’s federal court, one of which ended last month, federal prosecutors failed to win a single conviction. One reason for the courtroom setbacks can be traced to the ribald texts exchanged between the informant and his FBI handlers.

It’s no secret that informants, like the one in this sting, tend to have shady pasts, traits that make them easy targets for defense attorneys. But modern communications — texts, in this case — permitted a new line of attack: Defense lawyers used the questionable messages to savage the credibility and professionalism of FBI agents, who not only seemed to share their informant’s offensive sense of humor but also appeared to like him. While close relationships sometimes develop between agents and their informants, it is rare for such communications to become public. FBI agents closely guard the details of those relationships and are generally careful about what they put in writing.

In this case, the messages shocked former prosecutors, who said the texts hurt the agents’ credibility. “It was just foolish,” said Steven Levin, a former federal prosecutor in Maryland. “Jurors are loath to convict if they feel that both the informant and the law enforcement officers have acted improperly.”

During the most recent trial of six men and women on charges of paying a bribe to win business with a foreign government, defense attorney Steven McCool used the texts not only to attack the character of the informant but also to accuse an agent of being a bigoted, anti-gay misogynist.

For example, McCool asked the agent if his reference to “da hood” in a text was meant to have “racial overtones” and if he was expressing “a bias against gay people” when he texted the informant about dressing up in chaps and spurs while making a reference to the Village People.

Defense attorney Paul Calli, whose client was acquitted by a judge before his case even reached the jury, said such texts showed that “the FBI had established no appropriate boundaries” with the informant.

The agents, who declined interview requests, testified that the off-color texts were “operationally necessary” to build rapport with the informant and that they were not expressing biases in the messages.

Testimony indicates the agents never thought their colorful texts, which represented a tiny fraction of the messages exchanged during the investigation, would be made public.

In a statement, Justice Department spokeswoman Laura Sweeney said prosecutors have informed a federal judge that, in light of the first two trials, the government is evaluating “whether to continue to go forward” with the remaining prosecutions of 16 defendants, seven of whom had their cases end in hung juries.

The foreman of the jury in the most recent trial — a 36-year-old non-practicing lawyer — said in an interview that the texts hurt the prosecution, as did the agents’ evasive testimony about the messages’ lewd content.

“We found the government witnesses to have little credibility,” said the foreman, who spoke on the condition of anonymity to protect his privacy. He added that the investigation was poorly run and conceived — the agents made a basic math error, among other mistakes — and the “texts were one of many things that point to an absolutely amateurish operation.”

Setting up the sting

The texts emerged in a sting whose gen­esis can be traced to 2007,­ when Richard Bistrong, a tall, thin, tan and confident vice president at a police equipment company, came to the FBI’s attention. Although he appeared to be a successful jet-setter who lived in a 6,000-square-foot mansion in upscale Ponte Vedra Beach, Fla., his life was rending, according to his own testimony.

Bistrong, then 44, had a $15,000 monthly cocaine habit and routinely had sex with prostitutes, he testified. His second marriage, to a former U.S. diplomat, was cratering. In February 2007, he was fired by his company when it discovered he had been bribing foreign officials to get business. He also had accepted $1.3 million in kickbacks from suppliers.

Bistrong later pleaded guilty to conspiring to make corrupt payments to foreign officials, a violation of the Foreign Corrupt Practices Act, and agreed to cooperate with FBI agents in the bureau’s Washington Field Office. The FCPA bans bribes and kickbacks by individuals and companies to foreign officials to win business.

His role in what the FBI would later dub Operation Landslide was fairly straightforward: Bistrong, then a private consultant, approached executives in the arms and police supply industries and pitched a $12 million contract to outfit the presidential guard of the West African nation of Gabon.

The corrupt part: The deal would require a $1.5 million kickback to the Gabonese defense minister, Ali Bongo. What the participants did not know was that the entire transaction was a ruse and did not involve Bongo or anyone else in Gabon.

The informant started making his pitches in e-mails and over the telephone in the spring of 2009, telling potential targets that he had a deal in the works, thanks to a close friend, a Frenchman name Pascal Latour, who was really an undercover FBI agent. (Latour’s accent was described accurately by a defense attorney as sounding like Inspector Clouseau’s in the “Pink Panther” movies.)

Then came meetings between the targets, Bistrong and the undercover agents in posh hotel rooms. The FBI had set up surveillance equipment to capture Latour and Bistrong describing the deal. They never uttered the words “bribe” or “kickback,” however; instead, they called the illegal payment a “commission,” a vague term later exploited by defense attorneys.

Nicknames and banter

By the time the sting ended in January 2010 with the the arrests of 22 men and women, Bistrong and agents had developed a bond and easy banter.

The texts showed that Bistrong and Christopher Forvour, the case’s lead FBI agent, tended to communicate in sports cliches and created football-inspired nicknames for each other. Bistrong was called Tom Brady, the quarterback for the New England Patriots; the agent was Bill Belichick, the Patriots’ coach.

When Bistrong appeared to be showing signs of strain before a big meeting at Clyde’s restaurant in downtown Washington, Forvour texted him that “this week is like your Super Bowl. It is natural to be a little nervous before the big game.”

He also bucked up his informant with praise, telling him he could “sell snow to an Eskimo” and “it was all you, great work!” Apparently hoping to reassure his informant during a difficult patch, Forvour texted Bistrong, “FBI always wins, eventually, and you are on the right team.”

Another key member of the sting was Michael Dubravetz, an undercover FBI agent who pretended to be one of Bistrong’s employees. For months, they shared the same office and attended conferences and meetings.

Their text messages revealed a warm relationship that developed over cigars and exercise — they enjoyed taking long runs together. “I’m doing a 15-miler and it won’t be fun without you,” Bistrong texted the agent.

During the Memorial Day weekend in 2009, Dubravetz texted Bistrong that he was “smokin” his last Padron, an expensive brand of cigars he and the informant often savored when together.

“I’m lighting mine now! I got in trouble last night at dinner for too much extra staring,” Bistrong wrote, adding that the agent was “a bad influence.”

“Excellent work,” Dubravetz replied. “Getting in trouble actually helps keep the ladies on edge.”

Just before a conference in Washington, Bistrong joked that Dubravetz could watch him have sex with a female sales agent in their hotel suite. “Nasssssssty,” Dubravetz replied.

The informant and Dubravetz also shared nicknames, calling each other “sato.” Though the word is used by some Puerto Ricans to describe stray dogs, the agent and informant used it affectionately.

“My goodness is young sato going to have a good time in vegas,” Dubravetz wrote to Bistrong, “the two days before Old Sato finally makes it!!!!!”

“One day,” Bistrong replied. “I get there Saturday.”

“Whatever,” the agent texted. “By then, I’ll be broke and married! You’ll be too late!!!”

“Married?”

“Lil white chapel, Sato. Probably to a woman of ill repute!”

When Bistrong visited Italy in July 2009, he raved to Dubravetz about the country’s good-looking women, sparking a series of texts about Bistrong’s third wife and how she would kill him if he cheated on her.

“Then she would be a rich, lonely widow, heh, heh, heh,” Dubravetz texted.

“You would help her grieve, right?”

“Yup.”

Meanwhile, Bistrong didn’t hesitate to poke fun at the agent. Not even Dubravetz’s Irish girlfriend was off limits. In a text message to the agent, Bistrong joked he had downloaded a movie called “Irish Girls Go Wild in Barbados.”

“U [expletive] [expletive],” the agent texted back.

Read more from The Washington Post:

Petula Dvorak: A sad theme in Houston and Huguely cases

Battle looms for Va. Republicans

Ex-Army Corps of Engineers employee pleads guilty in scam

McDonnell to sign bill on breast density