Jorge Lorenzo took a thrilling race victory by just 0.019s from Marc Marquez as Valentino Rossi retires from the Italian GP.