SANTA ANA - Just as his trial was set to begin, a former U.S. Customs and Border Protection officer pleaded guilty Tuesday to raping two women, one in Long Beach and the other in Garden Grove, and was sentenced to six years in prison.

Miguel Lerma Jr., 33, of Fountain Valley, pleaded guilty to one count of forcible rape and one count of rape of an intoxicated person, both felonies, Deputy District Attorney Eric Scarbrough said.

Lerma met the first victim, who was in her 20s, through a mutual friend at the V20 club in Long Beach on Sept. 10, 2009, Scarbrough said.

The woman had several drinks before she blacked out and later woke up in the bushes at Redondo Avenue and East Hill Street in Long Beach early Sept. 11, 2009, Scarbrough said.

The victim flagged down a truck driver, who lent her his phone to call a friend and stayed with her until help arrived, Scarbrough said.

The prosecutor and defense attorney Rob Harley were working on pretrial motions, with plans to begin jury selection in the afternoon, when they negotiated the plea deal, Scarbrough said. Orange County Superior Court Judge John Conley accepted the plea bargain and sentenced Lerma.

Harley did not immediately return a message for comment.

Lerma met the second victim, who was a 20-year-old prostitute, on Nov. 14, 2010, Scarbrough said. He met her at the California Girls Gentleman's Club in Santa Ana, where he agreed to pay her for a sex act, Scarbrough said.

Lerma told the woman he had to get cash from an ATM, so she got in his car and they drove to a remote area in Garden Grove in the 11800 block of Cardinal Circle, Scarbrough said. Lerma said he remembered he had some money in the trunk and got out of the car, the prosecutor said.

"She gets spooked and gets out of the car and that's when the rape begins," Scarbrough said.

Both victims approved the resolution of the case, Scarbrough said.

Part of the motivation for the plea bargain was sparing the victims from having to testify, Scarbrough said.

The second victim "was very fearful of the defendant," Scarbrough said.

Investigators were able to link Lerma to the crime when the woman from the Long Beach case told them how she met her attacker, Scarbrough said. After investigators questioned the mutual friend they obtained a search warrant for Lerma's DNA, and that evidence linked him to both rapes, Scarbrough said.

Lerma was arrested March 31, 2011, while he was on his way to work.