Özil and global team-mate Ilkay Gündogan were pictured at the London Embassy in May alongside Erdogan, who was re-elected days later despite protests over his government's alleged systematic arrest of journalists, civil rights activists and political opponents.
"For me it didn't matter who was President, it mattered that it was the President".
"It is with a heavy heart and after much consideration that because of recent events, I will no longer be playing for Germany at global level whilst I have this feeling of racism and disrespect", he wrote.
'This decision has been extremely hard to make because I have always given everything for my teammates, the coaching staff and the good people of Germany.
Ozil earlier released two statements on Twitter.
"That is not why I play football, and I will not sit back and do nothing about it. Racism should never, ever be accepted", Ozil concluded.
Ozil said "the past couple of weeks have given me time to reflect" on the situation - adding that having been born in Germany to a Turkish family means that "I have two hearts, one German and one Turkish".
While Gundogan explained his part in the Erdogan photograph, Ozil opted to remain silent on the issue in the lead-up to the World Cup, leading to political turmoil.
Ozil has won 92 caps for his country, scoring 23 goals and playing a key role as Germany won the 2014 World Cup in Brazil.
In his statement on Sunday, Ozil said if he had not met the Turkish president, he would have been "disrespecting the roots of my ancestors".
Mesut Ozil said Sunday he was quitting the German national football team, citing "racism" in the criticism of him in the side's World Cup debacle.
The head of Germany's soccer federation, Reinhard Grindel, accused the players - whose families came to Germany from Turkey - of allowing themselves to be "exploited" by Erdogan for political purposes before a snap Turkish election in June.
Ozil detailed how Grindel attempted to benefit from the fall-out of the player's meeting with Erdogan, aiming to use it as a means to express his own political views and undermine Ozil in the process.
"I get that this may be hard to understand, as in most cultures the political leader can not be thought of as being separate from the person".
"Whatever the outcome would've been in the previous election, or the election before that, I would have still taken the picture".