Frank Cipriani entered a Bethesda home, wearing a disguise and posing as a building inspector. He faced his lover’s husband and pulled out a gun.

Then his fake beard fell off.

In that instant, an elaborate murder plot also unraveled. A startled Cipriani asked his target, “Do you know who I am?” And the intended victim was able to bolt out the front door to safety.

That account, as alleged by Montgomery County prosecutors, was laid out in court this week. Cipriani, 43, who is charged with attempted murder in the Aug. 17 incident, posted a $200,000 bond Tuesday and was released from the county jail, according to a corrections official. His attorney said he remains on leave from his staff position as a contracting officer for the U.S. Census Bureau.

“This is, on some level, very crazy behavior,” the attorney, Philip Armstrong, told a judge Monday. “I mean, he’s a responsible person with a responsible job.”

Armstrong said he doesn’t think that Cipriani ever had a handgun, only a BB gun. He said in court that his client is now receiving therapy and medicine for mental-health issues.

“We’re satisfied that when all of the evidence comes out we’re going to learn that, at worse, it was his intent to scare the complainant,” Armstrong said in an interview.

But authorities say there is evidence of something far more sinister. Cipriani, of Frederick, had been having an affair with a married woman and wanted his lover’s husband “out of the picture,” Assistant State’s Attorney Stephen Chaikin said in court Monday.

Chaikin said Cipriani hatched a plan that included furtively obtaining his intended victim’s fingerprints and typing a fake suicide note he planned to leave next to the corpse. Cipriani also is charged with assault and use of a handgun in a violent crime.

“We’re beyond probable cause,” Chaikin told District Judge Gary L. Crawford, saying the victim is lucky to be alive.

Cipriani, who is married and has children, grew up in New Jersey and attended Seton Hall University, according to court records and his Facebook page. On Facebook, Cipriani wrote that he knows Italian and Spanish and admires Leo Tolstoy, Thomas Jefferson and Mahatma Gandhi.

In 1989, when he was about 21, Cipriani pleaded guilty in New Jersey to criminal restraint and “threat-to-kill,” according to court records. Armstrong noted that his client was a young man at the time and that the case couldn’t have been serious because the judge imposed only four years’ probation, which ended after the second year.

In court Monday, Cipriani looked down much of the time. As the hearing ended, he blew his wife a kiss. Her eyes filled with tears, she did the same.

Cipriani joined the Census Bureau on or before 2004, according to court papers, and earns just over $100,000.

At some point, he began having an affair with a married colleague he supervises, Chaikin said. Then he came up with a plan.

Cipriani hosted a party and invited the husband and his wife. He took the husband to play a guessing game, Chaikin said. The husband was blindfolded, handed objects — such as picture frames — and asked to guess what they were.

“The police now think that that was to get his fingerprints,” Chaikin told the judge.

Cipriani also allegedly wrote an e-mail to the National Center for Missing and Exploited Children, pretending to be a 15-year-old girl who was having a sexual relationship with the husband, according to prosecutors. First he tried to ruin the man, Chaikin said, then he tried to kill him.

Authorities say that Cipriani came up with a ruse based on the fact that his target, and target’s wife, were remodeling a house. In a phone call, Cipriani posed as a building inspector and told the husband that they needed to meet at the house alone. “He lured a man . . . to his almost-death,” Chaikin said.

Cipriani arrived, pulled out a gun, handed his target a glass of water and told him to drink it, Chaikin said. The man feared he would be shot under his chin. But then part of Cipriani’s beard fell off, and Cipriani asked his target if he recognized him, authorities said.

“No, no, I don’t. I don’t know who you are,” the man responded, according to Chaikin.

The target was lying and recognized the assailant as his wife’s supervisor, according to charging papers. Moments later, a contractor arrived. The victim fled out for the front door, and Cipriani ran for the back, according to prosecutors.

Detectives found two fake suicide notes, charging papers say. They also found a hair they think came from the fake beard.

Staff researcher Magda Jean-Louis contributed to this report.