WASHINGTON — It is supposed to be a last line of defense against a Sept. 11-style attack on the United States. But a federal program that puts armed undercover guards on commercial airliners is in such disarray that it does little to deter terrorists, many of its employees say, and is being investigated by Congress.

Alcohol abuse among some in the Federal Air Marshal Service is so rampant that the Transportation Security Administration, which oversees the program, has had to monitor whether the armed guards show up for their flights sober, according to five people familiar with the situation. T.S.A. said its office of inspection makes quality assurance visits to ensure that the air marshals are properly prepared for their missions.

Female and minority air marshals said in court documents and interviews that they faced discrimination at work, including being subjected to sexually explicit messages and racist jokes and memes sent on government-issued cellphones. Other air marshals said they were fired or threatened with termination for minor infractions, while misconduct by managers was overlooked. Just 22 percent of the marshals thought their leaders maintained “high standards of honesty and integrity,” according to a federal employee survey completed last year, one of the lowest rankings among agencies.

“I ultimately decided to leave (retire) because I was denied the ability to leverage my experience for the good of the FAMs and I realize that I was part of a system which was putting the emotional well-being of FAMs at risk,” Kathleen Christian, who resigned last year as a clinical psychologist with the federal air marshals, said on Nov. 17 in a scathing email to several marshals. A copy was obtained by The New York Times.