WASHINGTON—For nearly six years, a senior Secret Service agent kept his extramarital affair with a Mexican woman a secret from the agency responsible for protecting the president.

But in the wake of an embarrassing prostitution scandal involving 13 agents and officers, Rafael Prieto's secret was revealed by a fellow employee amid concerns the Secret Service wasn't enforcing its rules consistently. With an internal investigation ongoing, Prieto apparently committed suicide last week, people familiar with the matter told The Associated Press.

Prieto, a married father assigned to the security detail for President Barack Obama, admitted the years-long relationship with a woman from Mexico to U.S. investigators when confronted. Before his death, he was the subject of an investigation focused on whether he violated agency rules that require disclosing relationships with foreigners, those familiar with the matter said. They spoke on condition of anonymity because they were not authorized to discuss Prieto's death or the investigation.

Secret Service rules require that employees with a security clearance notify the agency about any relationship with a foreign citizen to ensure that the person is not a risk to national security. There is no evidence that Prieto's relationship posed any security threat. Failing to disclose such a relationship would be not be a crime, but a violation of the agency's administrative rules.

Prieto was serving on the protective detail for Obama, though he was not on duty at the time of his death. As recently as 2009, he was identified as the resident agent in charge at the Secret Service's office in White Plains, N.Y. He had worked for the Secret Service for 22 years. He was 47, according to public records.

Prieto's apparent cause of death was carbon monoxide poisoning. He was found in his car with the engine running. His death was being investigated by Metropolitan Police in Washington and the medical examiner's office.

"Rafael Prieto had a distinguished 20-year career with the Secret Service that was marked by accomplishment, dedication and friendships," agency spokesman Edwin Donovan said in a statement. "The Secret Service is mourning the loss of a valued colleague."

The Secret Service protects the lives of the president, vice president and their families, and also investigates counterfeiting, bank fraud, computer hacking and other financial crimes.

The behavior of Secret Service agents and officers has come under scrutiny since 13 employees were implicated in a prostitution scandal in Cartagena, Colombia, in April.

Those employees were in the Caribbean resort city in advance of Obama's arrival for a South American summit. After a night of heavy partying in some of Cartagena's bars and clubs, the employees brought women, including prostitutes, back to the where they were staying. The incident became public after one agent refused to pay a prostitute and argued with her in a hotel hallway. Prieto was never in Colombia during the scandal.

Eight of those Secret Service employees have been forced out of the agency, three were cleared of serious misconduct and at least two are fighting to get their jobs back.

The scandal prompted Secret Service Director Mark Sullivan to issue a new code of conduct that barred employees from drinking within 10 hours of the start of a shift or bringing foreigners to their hotel rooms.