The 24-year-old, a who had been linked with a January move to London, has signed a "long-term deal", the Russian club said on their website.
The player will join up with his new team-mates at a training camp in Marbella later on Saturday.
A statement on the Shakhtar website read: "FC Shakhtar and FC Anji reached an agreement regarding Willian's move to the Russian club in a transfer worth 35million euros.
"Shakhtar thanks Willian for the years spent at the club, for his goals and professionalism. We wish our former player success in his new team."
In all since joining Shakhtar from Corinthians in 2007, Willian has played 221 games for the club, scoring 37 goals.
He is also a full Brazil international having made his debut in 2011.
He joins a number of fellow Brazilians in the Anzhi squad, as well as high-profile names Samuel Eto'o and Lassana Diarra, but not Christopher Samba. The centre-back joined QPR on Thursday.