The Fife institution was praised for its quality of teaching and overall student satisfaction.
The University of Dundee won the award for student experience and the University of Stirling took the home the prize for the best sporting university.
St Andrews ranks third among the best universities in the UK, behind Oxford and Cambridge, according to the guide.
Alastair McCall, editor of the Sunday Times Good University Guide, said: "St Andrews fully deserves to be mentioned in the same breath as Cambridge and Oxford when we talk about the very best that British higher education can offer.
"The league table proves it, but more importantly so do its students, who consistently rate St Andrews the best university for teaching quality."
Professor Sally Mapstone, principal and vice-chancellor of the University of St Andrews, said: "Our students see they are going to a university that delivers a high-quality experience all round - high-quality teaching in small groups from tutors who know them and understand their learning trajectory and wider career trajectory."
First Minister Nicola Sturgeon passed on her congratulations to the institution.
She said: "Scotland punches well above its weight in terms of international recognition and institutions like St Andrews play a key role in our standing on the world stage.
"With almost half of its students coming from Europe and the rest of the world it is well placed to take the message that Scotland is an open and welcoming nation to every corner of the globe."
"We are a community, a family, and that is why our student experience is the best in the UK, because we look out for each other."
The University of Strathclyde won Scottish university of the year.
Principal Professor Sir Jim McDonald said: "Students are at the heart of everything we do."