New Zealand win nail-biting first Test against Pakistan, become top ranked side