The 25-year-old, who has played two friendlies for Brazil, has switched allegiance to Vicente del Bosque's world champions and could make his debut in November's friendlies.
Costa is eligible under residency rules, having lived in Spain for more than five years.
A statement on the official website of the Spain national team confirmed Costa had signed a letter to D Julio Cesar Avelleda, secretary general of the
Brazilian Football Federation, stating his desire to commit to Spain.
The decision is a major boost for Spain, with Costa one of the most in-form strikers in Europe at the moment. He has scored 11 times in 10 Primera Division games this season and looks set to be a certainty in Del Bosque's World Cup squad for the tournament in Brazil next summer.