Jeremy Corbyn was just 2,227 votes away from having the chance to become Prime Minister in the general election, an analysis of marginal seats has revealed.

If the Labour leader had won seven seats narrowly taken by the Conservatives, he would have had the opportunity to form a “progressive alliance” with all other smaller parties, barring the Democratic Unionist Party (DUP).

The Labour Party has said it was prepared to form a coalition government, with Mr Corbyn announcing: “We are ready to serve.”

Jeremy Corbyn: We are ready to serve this country

With seven more seats going to Mr Corbyn, a coalition of Labour, the Liberal Democrats, the Scottish National Party (SNP), Plaid Cymru, the Green Party and one independent MP in the House of Commons would have held 321 seats — enough to block Theresa May and for Mr Corbyn to enter No 10. This figure excludes Kensington – expected to be another close-run contest – where counting was suspended until Friday evening.

The Green Party, SNP and Plaid Cymru had all spoken in favour of alliances, although the Liberal Democrats had ruled out joining with other parties during the election campaign.

The seven constituencies won by the Conservatives over Labour with the slimmest majorities were Southampton Itchen (majority 31); Preseli Pembrokeshire (majority 314); Hastings and Rye (majority 346); Chipping Barnet (majority 353); Thurrock (345 majority); Norwich North (majority 507); and Pudsey (majority 331).

General Election 2017: Big beasts who lost their seats Show all 7 1 /7 General Election 2017: Big beasts who lost their seats General Election 2017: Big beasts who lost their seats Nick Clegg Picture By Darren O'Brien/Guzelian Picture Shows Former MP, Nick Clegg delivers a speech despite losing the Sheffield Hallam Seat. Labour candidate, Jared O'Mara (Front), defeats Nick Clegg to take the Sheffield Hallam seat. picture taken 08/06/2017 Darren O'Brien General Election 2017: Big beasts who lost their seats Gavin Barwell LONDON, ENGLAND - OCTOBER 07: Gavin Barwell MP arrives at Number 10 Downing Street on October 7, 2013 in London, England. British Prime Minister David Cameron announced a Government reshuffle today. (Photo by Oli Scarff/Getty Images) Getty General Election 2017: Big beasts who lost their seats Angus Robertson General Election 2017: Big beasts who lost their seats Nicola Blackwood PA General Election 2017: Big beasts who lost their seats Alex Salmond PA General Election 2017: Big beasts who lost their seats Rob Wilson Mandatory Credit: Photo by Geoffrey Swaine/REX (1096138i) Rob Wilson, Conservative MP for Reading Funeral of Murdered Student Asha Muneer at Rivermead Leisure Centre, Reading, Britain - 28 Jan 2010 Rex Features General Election 2017: Big beasts who lost their seats Ben Gummer Minister for the Cabinet Office Ben Gummer arriving at 10 Downing Street, London for the weekly cabinet meeting. PA

There are 650 constituencies across the country, but Sinn Fein, which won seven seats, does not attend Westminster. The Speaker of the House, Conservative John Bercow, also does not vote.

Although Mr Corbyn was only 2,227 votes from having the opportunity to form a coalition government, Ms May’s Conservatives were only 287 votes from being able to form a working majority.

Had the Conservatives seized four seats from Labour – Dudley North (22 majority); Newcastle-under-Lyme (30 majority); Crew and Nantwich (48 majority); and Canterbury (187 majority) – Ms May would have been able to form a government without support from the Democratic Unionist Party, which won 10 seats.

The calculation comes as the Tories were reeling from the loss of their majority, which it had looked as though they would substantially increase when Ms May called the election in April.