Turkey lost 3-1 to Portugal on Thursday in the play-off semi-final.
Portugal took a 2-0 lead before Yilmaz pulled one back. Turkey were awarded a penalty with five minutes to go but Yilmaz skied his effort and the hosts added a third in stoppage time to set up a date with North Macedonia for a place in Qatar.
Yilmaz made his debut for Turkey in 2006 and won 77 caps, scoring 31 goals.
“I don’t know how I didn’t score, I'm still in shock. We upset our country. I'm sorry. I'm very sorry. This was my last World Cup chance. As of today, this is over," the 37-year-old told reporters.
“I said to myself it was a definite goal when we got the penalty. I started thinking about the future. I am disappointed because I never thought about missing it. I'm sorry. I'm going to score this penalty every night of my life, maybe without sleep, in my dreams.
“I wouldn't want to quit after a game like this, but I don't think it's right to continue. Thank you to my coaches. My decision to quit is not emotional. I make this decision logically. If extreme, unbelievable situations occur, then I will help.
“Our country needs to pass the flag on to our young friends. The new generation, the new structure. This is the right thing. My decision is not a result of disappointment, nor is it about a penalty. I think our brothers will do what is necessary from now on.”
Turkey have not qualified for the World Cup since finishing third at Japan/Korea in 2002.