It is the first time a university other than Oxbridge has been at the top of the The Times and The Sunday Times Good University Guide, which has been running since 1993.
Meanwhile, the University of Glasgow has been named Scottish University of the Year and is placed 12th in the UK-wide league table.
Editors of the guide said the way the University of St Andrews responded during the pandemic helped its performance in the league table as it flipped its small-class teaching model to online delivery during the pandemic.
It registered only a slight decline in satisfaction rates across the annual National Student Survey (NSS) while scores in other institutions have largely “fallen off a cliff”.
Alastair McCall, editor of The Times and The Sunday Times Good University Guide, said: “Never before has any university other than Cambridge and Oxford finished top of our – or any other – domestic ranking of universities.
“It is no fluke. The university has been closing in on the Oxbridge duopoly for several years, buoyed by outstanding levels of student satisfaction which have peaked during the past year of pandemic disruption on campus. The lead St Andrews now has over other universities in this key area of university performance is remarkable.
“Its wider contribution as a centre of teaching and outstanding research marks it out as a global player in the international higher education marketplace.”
In terms of academic research, St Andrews scored highly in the most recent Research Excellence Framework, especially for its work with Edinburgh University on chemistry and physics.
It is also renowned for its marine research, pioneering medical work and the Handa Centre for the Study of Terrorism and Political Violence.
Professor Sally Mapstone, principal and vice-chancellor of the University of St Andrews, which was third in the UK rankings last year, said: “I am thrilled for our students, staff and alumni. They are the people who made this happen.
“As one community, we strive constantly for excellence, and have a strategy that hasn’t been afraid to believe St Andrews could challenge at the very top by combining the best teaching, world-leading research, and an unswerving commitment to student satisfaction and achievement.”
She added: “I hope the fact that the staff and students of a small, Scottish institution have been able to break through the hitherto impenetrable Oxbridge ceiling will inspire others, and show that the status quo is only that if you allow it to be.”
The University of Glasgow was ranked second in the Scottish league table, followed by the University of Edinburgh, which was 13th in the UK rankings.
In fourth place was the University of Strathclyde, which was 17th in the UK rankings, while the University of Aberdeen was fifth in Scotland and 20th in the UK league table.
Professor Sir Anton Muscatelli, principal and vice-chancellor of the University of Glasgow said: “It is very encouraging to see the University of Glasgow once again rising in The Times and Sunday Times Good University Guide.”