Ozil, 29, earned 92 caps for his country and was part of the team that won the 2014 World Cup.
However he drew criticism at home after he met with Turkish President Tayyip Erdogan in May. He and Ilkay Gundogan - a team mate also of Turkish descent who likewise posed with Erdogan - were jeered in warm-up games before the World Cup in Russia.
At the height of the row Ozil made no comment on his meeting in London with Erdogan, an outspoken critic of Germany who was campaigning for re-election at the time.
He broke his silence in a string of statements on Twitter on Sunday with the third and final of these confirming his retirement.
"Is it because it is Turkey? Is it because I'm a Muslim? I think here lays an important issue" he said.
"The treatment I have received from the DFB & many others makes me no longer want to wear the German national team shirt. I feel unwanted & think that what I have achieved since my international debut in 2009 has been forgotten.
"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.
"I used to wear the German shirt with such pride and excitement, but now I don't. This decision has been extremely difficult to make because I have always given everything for my teammates, the coaching staff and the good people of Germany.
Image credit: Getty Images
"But when high-ranking DFB officials treat me as they did, disrespect my Turkish roots and selfishly turn me into political propaganda, then enough is enough. That is not why I play football, and I will not sit back and do nothing about it. Racism should never, ever be accepted."
His impassioned statement comes amid a political debate in Germany about an influx of immigrants that has seen a rise of the far right at the expense of traditional parties.
Ozil, who also plays for English club Arsenal, said German Football Association (DFB) President Reinhard Grindel had blamed him for Germany's poor performance in Russia.
"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 statement 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.
Germany is home to some 3 million people with Turkish roots.
"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," Ozil said in a statement on Twitter.
"My job is a football player and not a politician, and our meeting was not an endorsement of any policies.
"The treatment I have received from the DFB (German Football Association) and many others makes me no longer want to wear the German national team shirt," Ozil added.
"I feel unwanted and think what I have achieved since my international debut in 2009 has been forgotten.
"People with racially discriminative backgrounds should not be allowed to work in the largest football federation in the world that has players from dual-heritage families. Attitudes like theirs simply do not reflect the players they supposedly represent.