Pakistani Prime Minister Imran Khan has won a vote of confidence amid pressure by the opposition to leave power.