Rory held a two-shot lead midway through the final round but had to settle for third place at St Andrews.