Pakistan hold nerve to win close game