Allegri: 'Juve risked losing'