(CNN) A man has pleaded guilty to killing a Muslim teenager as she and her friends walked to a mosque in northern Virginia, officials said.

Darwin Martinez Torres, 25, accepted a plea deal Wednesday in a Fairfax County courtroom in a case that shook Virginia's Muslim community last year.

Martinez Torres, of Sterling, Virginia, had been indicted of eight counts, including abduction, rape, sexual assault and capital murder in the death of 17-year-old Nabra Hassanen. The plea deal allows him to avoid the possibility of a death sentence.

When he is formally sentenced in March, officials said, he will get life in prison without parole.

Martinez Torres, a native of El Salvador who immigration officials said is in the country illegally, was in his car when he first saw Nabra and her friends walking and riding bikes in the street and on the sidewalk.

Read More