The study found classes with large numbers of non-German pupils displayed less open prejudice and there were more friendships between races. Pupils, parents and teachers all became happier with the classroom situation. Anti-foreigner feeling was highest in classes with fewer foreigners. The survey comes as extreme-right attacks on foreigners are at an all-time high in eastern Germany, where racist attacks are 27 times more likely than in the west.
The findings will undermine the case of the German politicians who have been seeking to restrict the numbers of foreigners in inner cities to "reduce the possibility of conflict".
"The pupils notice that the foreign pupils are like them," said Dr Rainer Dollase, professor of psychology at the University of Bielefeld, who carried out the research in one of the largest studies into racism in schools.
The survey involved nearly 8,000 pupils aged 10 to 19, 3,200 parents and more than 400 teacers. It was carried out in the Western industrial cities of Wuppertal and Duisburg - which have 15 and 19 per cent foreign populations respectively - and the university town of Muenster.
It found that socio-economic factors had little effect but in classes where the percentage of non-Germans was under 10 per cent, xenophobic sentiments were expressed by 34 per cent of the German children.
Where foreigners made up more than 80 per cent of the class, only 16 to 19 per cent of German children expressed xenophobic sentiments.
The average percentage of pupils who always remained intolerant was about 14 per cent in all schools - far lower than expected, although consistent with international research which shows that even with contact some remain xenophobic.
The research goes some way towards explaining why xenophobia is so much higher in eastern parts of Germany, even though foreigners make up only 2.5 per cent of the population compared to 12 per cent in western states and nearer 19 per cent in larger western cities.
Racism in schools, 27