An Afghan asylum seeker has been accused of raping a 13-year-old girl in Germany.

The 18-year-old man was arrested on Thursday last week after the girl contacted police to say he had attacked her inside a home in Esslingen, near Stuttgart.

The man previously served a year in juvenile detention for attempted rape and was released in December last year under court supervision.

An 18-year-old Afghan asylum seeker has been accused of raping a 13-year-old girl at his apartment in the town of Esslingen, near Stuttgart, in Germany (stock image)

Police and prosecutors in Esslingen said the girl visited the man at his apartment in the city on Monday after becoming friends.

It was in the apartment that he allegedly forced her to have sex against her will.

The girl saw the man in the city's downtown area again on Wednesday when he threatened her, before she reported the attack to police.

He was arrested at his home the following day, Süddeutsche Zeitung reports. He has denied the allegations.

Police say the girl was attacked in Esslingen (pictured) on Monday, and reported the crime to officers on Wednesday. The man was arrested the following day and is in custody

A spokesman of the German Interior Ministry said it is not possible to tell whether the man will be deported while the investigation is ongoing.

But, the spokesman pointed out, deportation is mandatory for any asylum seeker handed a prison sentence of three years or more.

Asylum seekers can also be deported if they have received a prison sentence between one and three years for crimes directed against another person's physical integrity or sexual self-determination.