The 30-year-old Morocco international, who has made 18 appearances during his loan, has signed a deal until 2020.
They will seal a sixth consecutive Serie A title if they win at second-placed Roma on Sunday (19:45 BST).
Juventus face Lazio in the Italian Cup final on Wednesday and Real Madrid in the Champions League on 3 June.
Treble-chasing Juventus have exercised the option to make defender Medhi Benatia's loan move from Bayern Munich permanent for £14.4m (17m euros).