The 27-year-old will stay at the Otkrytiye Arena until June 2021 after completing a move to the Russian top-flight on the transfer deadline day.
Hanni scored 18 goals in 61 league appearances for the Constant Vanden Stock Stadium outfit and led the Purple-Whites to league triumph last season as the captain.
The former Nantes and Osmanlispor player will be aiming to help the People's Team - who sit third in the league table with 37 points from 20 games - to retain the league title when the Russian Premier League resumes from its winter break.
The Algerian forward is expected to join Massimo Carrera’s men at their training base in Marbella, Spain on Thursday.
“FC Spartak Moscow and FC Anderlecht signed a transfer contract for the transfer to our club captain of the Belgian team Sofian Hanni,” read a statement on club website.
“The agreement with the 27-year-old midfielder is concluded for three and a half years. Tomorrow, Hanni will arrive in Marbella, where the Spartacus conduct a training camp.”