Ozil, who has Turkish roots but was born in Germany, had been under fire since posing for a controversial photograph with Turkish President Recep Tayyip Erdogan in May which sparked questions about his loyalty to Germany's squad ahead of the tournament in Russia.
"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 in a statement on social media channels on Sunday.
Ozil, 29, said he had been unfairly blamed in Germany for the side's shock group stage exit at the World Cup.
Defending champions Germany crash out of World Cup at group stage
He insisted he was true to both his Turkish and German origins and did not intend to make a political statement by appearing with Erdogan a month ahead of elections in Turkey.
"I have two hearts, one German and one Turkish," said Ozil.
The Turkish government of Erdogan, who has championed a campaign against what Ankara sees as growing Islamophobia in Europe, hailed Ozil's move.
"I congratulate Mesut Ozil who by leaving the national team has scored the most beautiful goal against the virus of fascism," Justice Minister Abdulhamit Gul wrote on Twitter.
Turkey's Sports Minister Mehmet Kasapoglu, like Gul posting the picture of a smiling Ozil with Erdogan, added: "We sincerely support the honourable stance that our brother Mesut Ozil has taken".
The Arsenal midfielder blamed the German Football Federation (DFB) for failing to defend him against his most strident critics, lashing out at "mistreatment" in particular from DFB President Reinhard Grindel.
He said that Grindel and Germany coach Joachim Low had asked him to give a "joint statement to end all the talk and set the record straight" over the picture with Erdogan.
"Whilst I attempted to explain to Grindel my heritage, ancestry and therefore reasoning behind the photo, he was far more interested in speaking about his own political views and belittling my opinion,” said Ozil. "I will no longer stand for being a scapegoat for his (Grindel's) incompetence and inability to do his job properly. In the eyes of Grindel and his supporters, I am German when we win, but I am an immigrant when we lose."
Germany in shock as defending champions eliminated
The photo, which was published on the presidential website and the Twitter feed of the ruling party, came just before the June 24 polls Erdogan won to claim sweeping new powers.
Ozil said that despite the timing of the picture "it wasn't about politics or elections, it was about me respecting the highest office of my family's country".
"My job is a football player and not a politician, and our meeting was not an endorsement of any policies," he added.
Ozil said he could abide criticism of his performance on the pitch but not when it was linked to his ethnic background.
"If a newspaper or pundit finds fault in a game I play in, then I can accept this," he said. "But what I can't accept are German media outlets repeatedly blaming my dual-heritage and a simple picture for a bad World Cup on behalf of an entire squad," he added, calling it "right-wing propaganda".
"This crosses a personal line that should never be crossed, as newspapers try to turn the nation of Germany against me."
COMMENTS (1)
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ