Pakistan secured a 6-run win against Sri Lanka but fell short of the margin required to leapfrog New Zealand as they crash out of the World Cup at the Super 8 stage.