Image caption Oxford is the world's best university, according to the ranking

Two UK universities occupy the top spots in a global ranking for the first time.

The University of Oxford is top of the Times Higher Education World University Rankings, with Cambridge University second, up from fourth place last year.

A key factor in the rankings is income and both universities saw this rise in the past year, partly in the form of European Union research grants.

But this income could fall with Brexit, warned rankings director Phil Baty.

Times Higher Education, which compiles the rankings, said that margins were extremely tight at the top, with all the top-ranked institutions excelling against measures in teaching, research, citations, international outlook and income.

But Oxford and Cambridge saw significant increases in their total institutional income - up 24% and 11% respectively while their nearest rivals, the California Institute of Technology and Stanford University saw falls in income.

The researchers also point out that about a quarter of Cambridge's research income, and a fifth of Oxford's, come in the form of EU grants - a factor which they say underlines the risk Brexit could pose to the global performance of the UK's leading universities.

The top of the global ranking of 1,000 universities in 77 countries is dominated by US institutions.

Other UK universities in the top 50 are Imperial College London in eighth place; University College London, 16th; London School of Economics and Political Science, 25th; University of Edinburgh, 27th; and King's College London, 36th.

Times Higher: Top 20 Global Universities

1: Oxford University

2: Cambridge University

=3: California Institute of Technology

=3: Stanford University

5: Massachusetts Institute of Technology

6: Harvard University

7: Princeton University

8: Imperial College London

9: University of Chicago

=10: ETH Zurich - Swiss Federal Institute of Technology

=10: University of Pennsylvania

12: Yale University

13: Johns Hopkins University

14: Columbia University

15: University of California, Los Angeles

16: University College London

17: Duke University

18: University of California, Berkeley

19: Cornell University

20: Northwestern University

Image caption Cambridge University rose from fourth to second place

The researchers say the findings show "a widening gulf between the UK's super elite institutions and other universities", with just over half of the UK's top 200 institutions, dropping down the ranking.

Mr Baty said: "The UK higher education system is facing intense political pressure, with questions over the value for money provided by £9,250 tuition fees in England, our continued attractiveness to international students, the flow of research funding and academic talent post-Brexit, and even levels of vice-chancellors' pay.

"But one thing this new data makes absolutely clear is that the UK has many of the very best universities in the world and it has one of the world's strongest higher education systems.

"The data shows UK universities are consistently producing ground-breaking new research which is driving innovation, they are attracting international students and academic talent and are providing a world-class teaching environment.

"They are a huge national asset, and one that the country can ill-afford to undermine at a time when its place in the global order is under intense scrutiny."