Sharif, 63, received 244 votes in the 342-member lower house of parliament during the election conducted through a division of the House.
Makhdoom Amin Fahim, the candidate of the Pakistan People's Party that led the previous government, got 42 votes.
Veteran politician Javed Hashmi, the candidate of Imran Khan's Pakistan Tehrik-e-Insaf party, got 31 votes.
The result of the election was announced by Speaker Ayaz Sadiq.
The PML-N chief made history when he returned to parliament after a long gap of over 13 years.