The Chelsea striker won his fifth cap for Spain on Thursday in a 1-0 friendly defeat to France.
But he was substituted with 23 minutes remaining and tests on Friday revealed the extent of his injury, meaning he will replaced by young Barcelona forward Munir. The 19-year-old scored on his Liga debut against Elche last month.
A team statement said: "Diego Costa leaves the Spanish national team and will be replaced by FC Barcelona B striker Munir El Haddadi, who was under the management of [Albert] Celades in the Under-21 team.
"Diego Costa is sidelined in the national team due to a myofascial injury [in the] hamstring muscle in his left thigh.
"[The] injury was detected with an MRI scan carried out at noon in the Sanitas clinic of La Moraleja after the player expressed some discomfort during yesterday's match against France.
"All the tests carried out by the medical staff will be sent to Chelsea."
The 25-year-old is still yet to score for Spain since switching allegiances from Brazil, the country of his birth.
Costa has made a stunning start to the season, scoring four goals in three Premier League appearances for new club Chelsea.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.