On 17 May 2017, Allegri led Juventus to their 12th Coppa Italia title in a 2–0 win over Lazio, becoming the first team to win three consecutive championships. Four days later on 21 May, following a 3–0 win over Crotone, Juventus secured their sixth consecutive Serie A title, establishing an all-time record of successive triumphs in the competition. On 3 June 2017, Allegri entered his second Champions League Final in three years with Juventus, but suffered a 4–1 defeat to defending champions Real Madrid. On 7 June, Allegri renewed his contract with Juventus until 2020. Allegri took charge of his 200th game with Juventus on 9 February 2018, a 2–0 away win over Fiorentina. On 9 May 2018, Allegri won his fourth consecutive Coppa Italia title, in a 4–0 win over Milan. Four days later on 13 May, following a 0–0 draw with Roma, Allegri secured his fourth consecutive Serie A title, becoming the first manager in Europe's top five leagues to win four consecutive doubles. On 17 May 2019, after Juventus had already secured its fifth straight Scudetto under Allegri on 20 April, Juventus announced that he would leave the club at the end of the season. Allegri left Juventus in 2019 with a win percentage of 70.48%, the highest in the history of Juventus to date.