BERLIN — Germany awoke to a national debate on integration, racism and sports on Monday, as the news hit that one of its most celebrated soccer players was quitting the national team, saying that he was the victim of bigotry and hypocrisy.

Mesut Ozil, a star of Germany’s world champion 2014 team, announced his resignation in a series of lengthy social media posts, after enduring weeks of criticism for posing for a picture with President Recep Tayyip Erdogan of Turkey, and for his performance in Germany’s shocking early exit from this year’s World Cup.

“I’m a German when we win, but I am an immigrant when we lose,” wrote Mr. Ozil, who was born in Germany to parents who had immigrated from Turkey.

Mr. Ozil, 29, has been a symbol of modern German soccer and, by extension, a modern, diverse Germany — an attacking midfielder who has been voted player of the year five times by German fans and has played on the national team for nearly a decade. His sudden departure from the national team raised long-simmering questions about ethnic identity in Germany, and the intersection of sports and politics.