A deal to extend Castillo's contract at Olympiakos fell apart last week. Castillo, who was born in Mexico and raised in Uruguay, had three years left on his contract with Olympiakos.
Shakhtar, the Ukrainian runner-up, will play in the UEFA Champions League qualifying stage.
Financed by Ukrainian oligarch Rinat Akhmetov, whose fortune is worth an estimated $15 billion, Shakhtar is one of the richest clubs in Europe.
It just concluded the signing of 21-year-old Brazilian defender Ilsinho from Sao Paolo for $12 million. Ilsinho joins four other Brazilians at Shakhtar.
Shakhtar also signed Italian Cristiano Lucarelli from Livorno.