Ozil faced a barrage of criticism at home for having his photograph taken with Turkish President Tayyip Erdogan in May.
German football star Mesut Ozil said on Sunday he would no longer play for the national team because he faced "racism and disrespect" over his Turkish roots.
His impassioned statement is one of the strongest issued by a player in recent years on the subject of racism and met with mixed reactions.
It comes amid a political debate in Germany about an influx of 1.6 million migrants since mid-2014 that has seen a rise of the far right at the expense of traditional parties.
Ozil, 29, was a key member of Germany's World Cup-winning side in 2014 and has been voted by fans as the team's player of the year five times since 2011.
But the creative midfielder faced a barrage of criticism at home for having his photograph taken with Turkish President Tayyip Erdogan in May.
He and Ilkay Gundogan, a teammate also of Turkish descent who posed with Erdogan as well, were jeered by German fans in warm-up games before the World Cup in Russia.
Germany failed to qualify from the group stage, making their earliest exit from the tournament in 80 years and Ozil was one of the scapegoats for their unsuccessful title defence.
Ozil, who plays for English club Arsenal, said German Football Association (DFB) President Reinhard Grindel had blamed him for Germany's poor performance.
"In the eyes of Grindel and his supporters I am German when we win, but I am an immigrant when we lose," Ozil wrote in a lengthy statement in English posted on his Twitter account.
He added he did not feel accepted in German society despite paying taxes there, making donations to German schools and being part of the team that won the World Cup.
"It is with a heavy heart and after much consideration that because of recent events, I will no longer be playing for Germany at international level whilst I have this feeling of racism and disrespect," he said.
"I used to wear the German shirt with such pride and excitement, but now I don't," he said. "I feel unwanted and think that what I have achieved since my international debut in 2009 has been forgotten."
Many European footballers who play for national teams have a heritage in a different country but it is extremely rare for such players to cite racism resulting from those roots as a reason to abandon their national side.
There is also a debate about whether enough is done to stamp out racism in the sport, which many black players have faced over the decades often in the form of chants by opposing fans.
Ozil questioned whether there were criteria for being German that he did not meet and asked why he should be referred to as German-Turkish when fellow German football players Lukas Podolski and Miroslav Klose were not referred to as German-Polish.
"Is it because it is Turkey? Is it because I'm a Muslim? I think here lays an important issue," he said.
Germany's Social Democrat Justice Minister Katarina Barley said on Twitter: "It's alarming if a great German football player like Mesut Ozil no longer feels wanted in his country and doesn't feel represented by the DFB due to racism."
Veteran Greens lawmaker Cem Ozdemir, who has Turkish roots, said Ozil's photo was wrong and his explanation unconvincing but added: "The way the DFB leadership acted is at least as disastrous - Grindel is hacking our history of integration to pieces. Do they want young German-Turks to start playing for Erdogan soon? The DFB needs a fresh start."
But others criticised Ozil, with Thomas Bareiss, a senior member of Chancellor Angela Merkel's conservatives, saying Ozil's accusations of racism and a lack of respect were "out of place".
Mass-selling newspaper Bild said: "Ozil is revelling in the victim role that has nothing to do with reality".
Ozil has 92 caps for Germany and has scored 23 goals.
Earlier on Sunday Ozil defended the photograph in which he was pictured beaming with Erdogan, who was campaigning for re-election at the time.
"For me having a picture with President Erdogan wasn't about politics or elections, it was about me respecting the highest office of my family's country," he said.
"Two hearts, one German, one Turkish"
Relations between Germany and Turkey have soured amid a crackdown by Erdogan's government on suspected supporters of a failed military coup in July, 2016. Germany is home to some three million people with Turkish roots.
Germany and Turkey are both bidding to host the Euro 2024 tournament and UEFA will hold a meeting on Sept. 27 to choose between them.
Ozil said his mother had always told him to be respectful and remember his ancestry, heritage and family traditions, adding: "I have two hearts, one German and one Turkish."
Many fans and politicians in Germany were angered by the photo with Erdogan and it was widely criticised by politicians and Germany's football federation, which argued that Erdogan did not sufficiently respect German values.