Updated

An Afghan migrant told a German court Monday he raped and murdered a 19-year-old medical student who had cycled past him when he was drunk and high on drugs.

The dpa news agency reported Hussein K., whose last name was withheld in adherence to Germany's privacy laws but who has been widely identified as Hussein Khavari, admitted his crime to the Freiburg state court and apologized to the victim’s family.

Hussein testified he pulled the student, identified in media reports as Maria Ladenburger, from her bicycle last October before raping her and dragging her unconscious body to a river, where she drowned to death.

Pleas aren't entered in Germany, and confessions, which can mitigate sentences, are common.

Hussein, who entered Germany in 2015, maintains he was 18 at the time of the crime, but prosecutors say he was 22, which could mean the difference between a 15-year youth sentence or an adult life sentence.

Hussein was born in Afghanistan, but moved to Iran at the age of 13. After "problems with the police," he then fled the Islamic Republic for Turkey, before moving on to Greece and finally Germany, according to a report by German newspaper Deutsche Welle.

The murder trial has gripped Germany and sparked a nationwide debate over the country’s migration policy, as Hussein arrived in Germany during the height of the migrant crisis in the autumn of 2015 and registered as an unaccompanied minor.

German Chancellor Angela Merkel, right, and the Governor of the German State of Bavaria, Horst Seehofer, left, address the media about the migrant influx. (AP)

During an investigation following his arrest last December, it was revealed the Afghan had previously been sentenced to 10 years in a Greek prison for almost killing a woman by pushing her off a cliff. He was released after spending just over a year behind bars in order to make space in Greece’s overcrowded prisons.

Following his release he joined the wave of migrants fleeing the violence in places like war-torn Syria to sneak out of Greece and into Germany.

The revelations of Hussein’s past reignited anger at German Chancellor Angela Merkel's decision to allow hundreds of thousands of refugees into the European country in 2015. Outside the courtroom on Monday, about 10 supporters from the far right Alternative for Germany gathered to protest Merkel’s policies.

The Associated Press contributed to this report.