Brooks Koepka won his second consecutive PGA Championship despite almost losing a seven-stroke lead in Sunday's final round.