David Kirk was a career Marine pilot with a top-secret security clearance and a record of flying classified missions. He was in the cockpit when President George W. Bush and Vice Presidents Dick Cheney and Joe Biden traveled around the nation's capital by helicopter.

With credentials like that, Kirk was stunned to fail a lie detector when he applied for a pilot's job with U.S. Customs and Border Protection, which guards 6,000 miles of border with Mexico and Canada. After two contentious polygraph sessions that lasted a combined eight hours, Kirk said, he drove home "with my tail between my legs," wondering how things had gone so wrong.

Related Videos...

Two out of three applicants to the CBP fail its polygraph, according to the agency -- more than double the average rate of eight law enforcement agencies that provided data to The Associated Press under open-records requests.

It's a big reason approximately 2,000 jobs at the nation's largest law enforcement agency are empty, with the Border Patrol, a part of CBP, recently slipping below 20,000 agents for the first time since 2009. And it has raised questions of whether the lie detector tests are being properly administered.

CBP Commissioner Gil Kerlikowske said the failure rate is too high, but that it's largely because the agency hasn't attracted the applicants it wants. He and other law enforcement experts contend the polygraphs are generally working as intended at the agency, which has been trying to root out bribery and other corruption.

But others, including lawmakers, union leaders and polygraph experts, contend that the use of lie detectors has gone awry and that many applicants are being subjected to unusually long and hostile interrogations, which some say can make people look deceptive even when they are telling the truth.

Republican Sen. Jeff Flake of Arizona said he suspects CBP examiners fail applicants to justify their own jobs. He said he worries applicants are being wrongly branded with a "scarlet letter" in the eyes of other potential government employers.

"There seems to be no good explanation, and when we hear so many anecdotal stories, it starts to look like a trend where they feel like they have to fail them, a certain number," he said. "It makes you angry that people would be put through that."

In December, the Homeland Security Department's inspector general said it was reviewing whether CBP's polygraphs are effective in hiring. The hiring difficulties have become so acute that the Border Patrol recently took the unusual step of asking Congress to use money earmarked for 300 jobs for other purposes. That raises doubts about President-elect Donald Trump's pledge to add 5,000 agents.

ILLEGAL IMMIGRANT SUSPECTED OF SEXUALLY ASSAULTING 5-YEAR-OLD IN CALIFORNIA

Taking a polygraph became a hiring requirement at CBP in 2012 after a huge hiring surge led to more agents getting arrested for misconduct.

James Tomsheck said that when he was CBP's chief of internal affairs from 2006 to 2014, about 30 applicants admitted during the lie detector test that they were sent by drug cartels; one said he killed his infant son.

One applicant revealed his brother-in-law wanted him to smuggle cocaine on the job, and another said he used marijuana 9,000 times, including the night before his test, according to the Government Accountability Office.

Interviews with six applicants who failed to clear the polygraph fit a pattern: The examiner abruptly changes tone, leveling accusations of lying or holding something back. The job-seeker denies it and the questioning goes in circles for hours. Some are invited for a second visit, which ends no differently.

Luis Granado applied to the Border Patrol in 2014 with military experience and a bachelor's degree from the University of Arizona. His father is an agent, and Granado used to proudly try on the badge as a boy.

"This was my dream job," said Granado, 31, who is now a full-time Air Force reservist in Tucson, Arizona. "I wanted to follow in my dad's footsteps forever."

He said the examiner scolded him for answers that were "too emphatic, too fast" and told him to stop grinding his teeth.

Granado said the examiner was troubled by an admission that he cheated on a test in high school. When he denied ever belonging to a cartel or terrorist group, the examiner stopped and said, "Well, I think you're being deceptive," according to Granado. After two sessions that lasted a total of 12 hours, his conditional job offer was rescinded.

CBP declined to comment on individual cases.

CBP's Kerlikowske put the agency's polygraph failure rate at about 65 percent. The AP asked law enforcement agencies across the country for two years of lie-detector data for job applicants, including police departments in the nation's 10 largest cities and in major towns along the Mexican border. The eight that supplied numbers showed an average failure rate of 28 percent.

Tomsheck said that when he was CBP's internal affairs chief, other federal agencies, including the FBI and Secret Service, had failure rates of less than 35 percent. The U.S. Drug Enforcement Administration, the only federal agency that supplied data to the AP, failed 36 percent in the last two years.

Mark Handler, editor in chief of the American Polygraph Association, said failure rates of about 30 percent are typical in law enforcement hiring.

Kerlikowske explained that the agency isn't getting the applicants it wants because the relatively new CBP, created in 2003, "doesn't have a brand" and is unfamiliar to some.

Among other possible reasons offered by some experts for the agency's failure rate: CBP may have higher standards than local departments, and it get less-experienced applicants who have never taken a lie detector before.

The duration of CBP's testing strikes some experts as unusual.

"If there's an exam that lasts four to eight hours, your polygrapher is either incompetent or a fool or both," said Capt. Alan Hamilton, commanding officer of the Los Angeles Police Department's recruitment and employment division. His department's exams last no longer than 90 minutes.

Handler said prolonged, accusatory interviews can lead to failures for people who are telling the truth. Lie detectors measure blood pressure, sweating and breathing.

Polygraphs are generally not admissible in court, and federal law bars private employers from using them to hire. The military doesn't use them to screen enlistees, and some law enforcement agencies don't use them in hiring, including the New York Police Department, U.S. Marshals Service and Immigration and Customs Enforcement.

CARTELS, SMUGGLERS EXPLOIT BORDER WALL FEARS AHEAD OF TRUMP PRESIDENCY

CBP, under pressure to hire, recently loosened standards on previous marijuana use and, under a law that took effect in December, can waive polygraphs for veterans with top-secret clearances.

Kirk, 47, of Friendswood, Texas, applied to CBP in 2013 after 20 years as a Marine officer and calls it one of the worst experiences of his life. In the Marines, "one of our biggest mantras is our honesty and integrity," he said. "Someone calling me a liar, I take it very personally."

During the 2013 polygraph exams, he said, he was accused of cheating on his wife and mishandling classified information and was told he acted like a drug trafficker trying to infiltrate the agency. Kirk vehemently denies the allegations.

RYAN TELLS UNDOCUMENTED FAMILY DEPORTATION FORCE ‘NOT HAPPENING’

The accusation of marital infidelity "almost made me want to jump across the desk," said the father of four. He told the examiner that he tried marijuana in college and says the biggest mark on his record is a speeding ticket.

"They treated me like a criminal," said Kirk, now a private pilot. "I don't know who was better qualified than me to fill this position."