Bivsi Rana, 15, was born in Germany to Nepalese parents. In May she was deported with the rest of her family.
Her classmates protested and lobbied on her behalf against the deportation, drawing hundreds of people to rally under the slogan "Bring Bivsi back".
Officials called it a "unique case" and said Bivsi was "de facto German".
Mayor of Duisburg Sören Link said: "The fact that we have managed to resolve this difficult situation lifts a burden from my shoulders."
Bivsi's parents moved to Germany in 1998, fleeing civil conflict in their native Nepal, but their applications for asylum were denied. Their repeated appeals were rejected. Fearing political repercussions at home Bivsi's father, Mr Rana, initially applied for asylum under a false name and has since called this "the worst mistake" of his life.
But Bivsi herself was born and brought up in Germany.
On the last Monday in May, Bivsi was in class at school in Duisburg, in north west Germany, when she was told she had to pack her things and leave. That same day she and her family were deported to Nepal, a country Bivsi had never visited before.
Class teacher Sascha Thamm told German media afterwards that all the girls in the class cried and Bivsi's best friend broke down to the extent that an emergency doctor had to be called.
Mr Thamm said Bivsi was a kind, engaged student who was good at German and science and helped teach swimming lessons.
Bivsi has been living in Nepal with her family and, according to reports, has been unable to find a new school there due to language issues.
She has now been given a study visa enabling her to return Germany while she finishes her education. Her parents can return with her.
North-Rhine Westphalia state's integration minister Joachim Stamp said: "This is a unique case and generalisations cannot be drawn from it.
"The right of the child stood in the foreground in this decision.
"Bivsi was born in Germany and grew up here - she is de facto a German child."
Bivsi is reported to be "totally happy" with the decision, and her parents are reported to be "overjoyed".