Mr Anwar, a criminal defence solicitor, received almost 4,500 votes from students.
The only female nominee, Lady Hazel Cosgrove, received the second highest number of votes at 1,400.
Mr Anwar will take over from intelligence whistleblower Edward Snowden who has served three years in the role.
Sir Vince Cable came third on 535 votes, with right-wing journalist Milo Yiannopoulos fourth on 533.
"It's a tremendous result - a landslide victory", Mr Anwar said.
"For me, it just encompasses the fact that students at Glasgow University do care.
"They've sent a message of unity against hatred and bigotry. They want their voices to be heard - they've fought for far too long and have been ignored."
He added: "They've entrusted me to be an active, working rector.
"I intend to keep all my pledges in the manifesto to fight for students, all students, to fight for the issue of mental health, to fight over rocketing rents, to fight over the issue of Brexit and to ensure that no student should suffer in silence at this university and that they get the backing and funding and support of everyone at this campus."
First Minister Nicola Sturgeon offered her congratulations to Mr Anwar on Twitter.

The sustainable development white paper was launched at a school in Blaenavon, Torfaen, dubbed a good example for helping the wider community.
However, the Conservatives said urgent action was needed amid growing environmental concerns.
And Welsh language campaigners feared their cause could fall lower down the priorities of public bodies.
Delegates from organisations including local councils were told that Blaenavon Heritage Primary School was chosen as the location for the launch as it provided a wide range of courses and services across the area for residents with a number of public bodies working together.
"Our approach is very much rooted in Welsh values, with a focus on fairness, pride in our communities and our heritage," said John Griffiths, environment and sustainable development minister.
"The proposals set out in this White Paper are about focusing on the social, economic and environmental well being for Welsh people and Welsh communities over the long term."
The Sustainable Development Bill includes:
For the Conservatives, shadow environment minister Russell George said: "While this consultation and its influence on future policy is extremely important, we have long called for Labour ministers to get a grip on sustainable development.
"With greenhouse gases on the rise, mobility policy failing, health inequalities getting wider and wildlife habitats in decline, it's more important than ever that we see urgent improvements."
Meanwhile, the Welsh Language Society (Cymdeithas yr Iaith Gymraeg) has concerns.
Sustainable communities spokesperson Toni Schiavone said: "The government's language strategy is completely clear that Welsh needs to be mainstreamed in all its departments, especially where the work affects the future of Welsh speaking communities.
"However, under this Bill, there is a risk that public bodies will downgrade the Welsh language as a policy consideration.
"The government intends to make sustainable development public bodies' central organising principle.
"In that context, it's essential that the welfare of the Welsh language is part of the definition of sustainable development."
The consultation runs until March with a number of public events from January.

The 25-year-old Serbia striker arrived at Celtic from Sporting Gijon on deadline day last August.
But he has failed to become a first-team regular, making only one substitute appearance this season.
And the arrival this summer of Nadir Ciftci from Dundee United was a further indication that the £2.3m signing's future may lie elsewhere.
Scepovic has made 26 appearances for Celtic and scored six times.
Human rights lawyer Aamer Anwar has been elected as the new rector of the University of Glasgow.
[NEXT_CONCEPT]
The Welsh government wants to introduce a new law to protect the "well-being" of community life.
[NEXT_CONCEPT]
Stefan Scepovic has left Celtic to join the Spanish La Liga club Getafe on a season-long loan deal.