It started to rain that Halloween night, and the three teenage girls decided to head home. As they walked near a Woodbridge shopping center with their bags of candy, they texted, talked on the phone, laughed. Suddenly, they sensed someone behind them in the dark.

“I felt like a gun on my back,” one testified. “He said: ‘Don’t move. Do you have any money, do you have anything?’ We said we didn’t have anything but our bags of candy. That’s when he directed us behind the building.”

It was the beginning of a terrifying ordeal and what authorities think were the last two in a decades-long series of rapes spanning the East Coast. In a Prince William County courtroom Thursday, the young women for the first time confronted the man police allege raped two of them in 2009, describing in detail how they were accosted, led into the woods and brutally attacked on a night that was supposed to be about childhood fun.

Aaron H. Thomas, 40, did not look at the women as they testified, staring at the table in front of him and at one point putting his forehead on it. He is, police say, the elusive “East Coast Rapist,” linked by DNA to nearly a dozen rapes in Virginia, Maryland and Connecticut dating to the 1990s.

Thomas, bearded and wearing an orange jumpsuit and waist chains, appeared in court for a preliminary hearing, the start of a process that could result in a trial at which he could face a maximum of life in prison. Juvenile and Domestic Relations Judge William Alan Becker sent the case to a grand jury for possible indictment.

Speaking with poise and clarity, the young women recounted a night that began with a 7-year-old’s party, taking a group of youngsters out trick-or-treating and then following suit when they saw how much candy they might be able to collect. On the way home, it started to rain.

“But we didn’t make it back,” one of the teenagers testified.

Instead, they were forced to drop their bags of candy at a wood line and walk down a steep slope. At the bottom, they were ordered to face away from the man and then lie on the ground.

“Don’t say anything or I’ll kill you,” he said, according to testimony.

He then raped two of the girls. The Washington Post generally does not identify victims of sex crimes.

“I was scared,” said one victim. “I was praying. I thought that was it. I thought I was going to die.”

The third teenager, who was cowering in the wet leaves, said she knew her friends were being raped but wasn’t able to see it.

It was her, though, who probably interrupted the attack through her deft attempts to call for help. Having hidden her cellphone in her sleeve, she texted her mother and others that her friends were being raped, at one point reaching a 911 operator while fearing that the man would discover what she was doing. When police sirens approached, the man ran.

Assistant Commonwealth’s Attorney James Willett told the court that the third teenager would have been attacked had police not arrived. “He just didn’t have time to do it,” Willett said.

On cross examination, defense attorneys Ronald Fahy and Jennifer Zary were able to establish that none of the teenagers could identify Thomas as their attacker, because they knew only that the rapist was wearing a dark hoodie, a ski mask and dark jeans. And none could say for sure that the man had a gun, just that they believed he did.

Thomas did not speak during the hearing, and prosecutors presented a doctor’s report indicating that he is competent to stand trial. His mother attended part of the hearing, but left during the first teenager’s testimony.

Police and prosecutors said the Halloween attack was one in a series of at least 17 and that it carried several hallmarks of Thomas’s alleged crimes. It involved approaching vulnerable strangers with a weapon; the rapes took place in a secluded area likely known to the rapist; and he was able to escape without witnesses noticing much about him. Perhaps most important, however, Thomas’s DNA was left at the scene, police said

For years, police knew they were looking for one man in connection with rapes in Prince George’s, Fairfax and Loudoun counties and in New Haven, Conn., having found the same DNA at many of the scenes. After the Halloween rapes, The Post published a lengthy investigation and a police task force aggressively distributed sketches of the attacker and offered a reward.

Thomas, a long-haul trucker who grew up in Prince George’s County, at one point owned a home in Woodbridge not far from the scene of the rapes.

After Thomas’s name was culled from a computer program as a potential suspect — and after an anonymous tip — police collected a DNA sample from a cigarette he discarded and quickly arrested him when it was a match.

Prince William County police 1st Sgt. Liam Burke told the court that Thomas brought up the Halloween rapes on his own when he talked to detectives.

“He knew he was there for Halloween night,” Burke said. “He said he saw the girls walking, got an urge, had a fake gun and brought them into the woods and sexually assaulted them.”

Commonwealth’s Attorney Paul B. Ebert said he expects the case will go before a grand jury in April. If convicted, Thomas could face life in prison on charges of rape, abduction and use of a weapon.