A spokesman said the university recognised the "devastating impact" that climate change could have and the "need to reduce the world's dependence on fossil fuels".
The university is withdrawing Â£18m of investments over the next decade.
It comes after students had mounted a campaign calling for the change.
More than 1,300 were involved in the campaign, which included rallies and fake oil spills.
David Newall, secretary of the university's governing body, said: "The university recognises the devastating impact that climate change may have on our planet, and the need for the world to reduce its dependence on fossil fuels.
"Over the coming years we will steadily reduce our investment in the fossil fuel extraction industry, while also taking steps to reduce our carbon consumption."
The university will freeze new investments in fossil fuels and, over 10 years, divest its hydrocarbon investment which is around 4% of its total endowment.
Glasgow joins 13 American universities and many other institutions who together have pledged to withdraw more than $50bn in assets from the fossil fuel industry.
Just before the recent New York climate summit, the heirs to the Rockefeller fortune announced they planned to pull their funds from fossil fuels.
Campaigners say that, so far, 181 institutions and 656 individuals have agreed to withdraw their money from fossil fuels.
Students in many universities are lobbying for governors to divest but are often meeting strong resistance from governing bodies charged with prudent investment of university funds.
Glasgow has confirmed that its commitment is subject to reassurance that the financial impact for the university is acceptable. Its effects will be monitored by the governing body.
Campaigner Callum Shaw, said: "Among students the argument about whether climate change exists is not really happening - people have read the academic papers and are not in any doubt. We started out as a small group, but the campaign quickly gained traction."
Other British universities are also set to consider the issue.  The School of Oriental and African Studies is expected to make a divestment decision in the next month.
Decisions are also imminent from a handful of other institutions including the University of Edinburgh. Oxford University and its colleges are consulting on divestment from $3.8bn worth of investment. More than 1,000 Oxford students and academics have joined the campaign.
Scientific reports have suggested it will only be possible to burn about a third of the fossil fuels already discovered and keep a stable climate.
Mary Church from Friends of the Earth Scotland said: "Well done Glasgow for becoming the first university in the UK to take this hugely important step. Not only is this great news for the planet, but it also makes good financial sense [because] at some point this carbon bubble is going to have to burst."
So far the divestments worldwide have not dented investments in the fossil fuel industry. Oil, gas and coal companies form one of the world's largest asset classes, worth nearly $5 trillion at current stock market values. They are liked by investors because of their profits and shareholder yield.
The campaigners hope eventually to emulate the success of the anti-apartheid campaign by making fund-holders embarrassed to invest in fossil fuels.
Follow Roger @rharrabin
Glasgow University has become the first in the UK to announce that it will sell off the shares it holds in companies that produce fossil fuels.