HERAT, Afghanistan — The two teenagers met inside an ice cream factory through darting glances before roll call, murmured hellos as supervisors looked away and, finally, a phone number folded up and tossed discreetly onto the workroom floor.
A car burned by a crowd during a riot that took place after the police rescued two teenagers from a group of men who had demanded that they be hanged or stoned for their relationship.
It was the beginning of an Afghan love story that flouted dominant traditions of arranged marriages and close family scrutiny, a romance between two teenagers of different ethnicities that tested a village’s tolerance for more modern whims of the heart. The results were delivered with brutal speed.
This month, a group of men spotted the couple riding together in a car, yanked them into the road and began to interrogate the boy and girl. Why were they together? What right had they? An angry crowd of 300 surged around them, calling them adulterers and demanding that they be stoned to death or hanged.
When security forces swooped in and rescued the couple, the mob’s anger exploded. They overwhelmed the local police, set fire to cars and stormed a police station six miles from the center of Herat, raising questions about the strength of law in a corner of western Afghanistan and in one of the first cities that has made the formal transition to Afghan-led security.
The riot, which lasted for hours, ended with one man dead, a police station charred and the two teenagers, Halima Mohammedi and her boyfriend, Rafi Mohammed, confined to juvenile prison. Officially, their fates lie in the hands of an unsteady legal system. But they face harsher judgments of family and community.
Ms. Mohammedi’s uncle visited her in jail to say she had shamed the family, and promised that they would kill her once she was released. Her father, an illiterate laborer who works in Iran, sorrowfully concurred. He cried during two visits to the jail, saying almost nothing to his daughter. Blood, he said, was perhaps the only way out.
“What we would ask is that the government should kill both of them,” said the father, Kher Mohammed.
The teenagers, embarrassed to talk about love, said plainly that they were ready for death. But they were baffled by why they should have to be killed.
Mr. Mohammed, who is 17, said: “I feel so bad. I just pray that God gives this girl back to me. I’m ready to lose my life. I just want her safe release.”
Ms. Mohammedi, who believes she is 17, said: “We are all human. God created us from one dirt. Why can we not marry each other, or love each other?”
The case has resonated in Herat, in part because it stirred memories of a brutal stoning ordered by the Taliban last summer in northern Afghanistan.
A young couple in Kunduz was stoned to death by scores of people — including family members — after they eloped. The stoning marked a brutal application of Shariah law, captured on a video recording released online months later. Afghan officials promised to investigate after an international outcry, but no one has faced criminal charges.
The immediate response to the violence in Herat was heartening by comparison. Top clerics declined to condemn the couple. Police officers risked their lives to pull the two teenagers to safety and deposit them into the legal system, rather than the hands of angry relatives. And the police reported that five or six girls had fled the city with their boyfriends and fiancés in the weeks after the riot.
After discussing the case, the provincial council decided that Mr. Mohammed and Ms. Mohammedi deserved the government’s protection because neither was engaged, and because each said they wanted to get married.
“They are not criminals, even if they have committed sexual activities,” said Abdul Zahir, the council’s leader.
But so far, their words have not freed either of the teenagers or lent them any long-term security.
Ms. Mohammedi was initially taken to the only women’s shelter in this province of more than 1.5 million people, but the police transferred her quickly to the city’s juvenile detention center, a sun-washed building where about 40 girls and 40 boys sleep in separate dormitories. The police said they had referred the teenagers’ cases to prosecutors.
“From their point of view, she committed a crime,” said Suraya Pakzad, director of Voices of Women Organization, a rights group that provided Ms. Mohammedi with a bed for one night.
Ms. Pakzad said most of the women and girls in the shelters of western Afghanistan had fled forced or abusive marriages, or had been ostracized from their communities for dating young men without their families’ approval. Male relatives often punish such transgressions with beatings or death.
But in separate interviews at the juvenile jail, Ms. Mohammedi and Mr. Mohammed said they had not worried about such things.
He did not think about the rage that would erupt if a young Tajik man picked up a Hazara girl in a neighborhood dominated by conservative Hazaras, members of one of Afghanistan’s many ethnic minorities. “It’s the heart,” Mr. Mohammed said. “When you love somebody, you don’t ask who she is or what she is. You just go for it.”
They had much in common. His father was dead, as was her mother. They described each other as quiet and polite, both a little shy. They liked the same sappy songs that float over from Iran.
After six years of primary school, Ms. Mohammedi had wanted to study English and take computer classes, but she said her family told her it was a waste of time, and sent her to work at the ice cream factory, for $95 a month.
There, at least, they found each other. Mr. Mohammed spent a month stealing hellos before Ms. Mohammedi tossed her phone number at his feet.
The couple talked on the phone most nights, even though her stepmother disapproved. After a year, they decided they were fed up with hiding their relationship. They would meet, go to the courthouse and get married. Mr. Mohammed persuaded an older cousin to take him to the village of Jabrail, where she was waiting in the town square.
They had not driven 30 feet when a yellow Toyota Corolla blocked their path and angry men jumped out. Ms. Mohammedi was not hurt in the melee that followed, but the crowd beat up the cousin and pummeled Mr. Mohammed until he collapsed.
“We knew they would kill us,” she said.
They now spend the days at opposite ends of the same juvenile jail, out of each other’s sight. Mr. Mohammed nurses the wounds still visible in his swollen face and blood-laced eyes, and Ms. Mohammedi has been going to classes and learning to tailor clothes.
Both say they want to be together, but there are complications. Family members of the man killed in the riot sent word to Ms. Mohammedi that she bears the blame for his death. But they offered her an out: Marry one of their other sons, and her debt would be paid.