Image copyright Pacemaker Image caption Walking away: Mike Nesbitt is to stand down as leader of the Ulster Unionist Party

The DUP has marginally held on to its position as the largest party in Northern Ireland with a total of 28 seats in the assembly election.

Sinn Féin has increased its vote in the poll and has 27 seats.

Ulster Unionist leader Mike Nesbitt announced he is to resign after poor results for his party.

Four former Stormont ministers - two from the DUP, one from the SDLP and one from the Ulster Unionist Party - lost their seats.

All 90 seats have now been confirmed.

Image copyright Stephen Hamilton Image caption The Mid-Ulster count gets underway in Ballymena

The turnout for the election is the highest since the vote which followed the 1998 Good Friday Agreement.

A total of 64.8% of the electorate voted - up 10 points on last year - beating the 2003 figure by 0.8%.

Mr Nesbitt said the electorate had rejected his message and he had to take responsibility for what happened.

End of the night analysis - BBC News NI's Political Correspondent Gareth Gordon

This election has produced more than its fair share of storylines. Having lost a number of prominent figures including former deputy leader Danny Kennedy and Jo-Anne Dobson, UUP leader Mike Nesbitt said it would be the height of hypocrisy if he did not take full responsibility. He leaves his party facing an uncertain future.

It has also been a difficult election for the DUP. Party Chairman Lord Morrow and former minister Nelson McCausland are among those who lost their posts.

But it has been a great election for Sinn Féin. Their vote is up almost 4% and they are breathing down the DUP's neck.

Alliance looks like coming back with its eight seats. For the SDLP, the high points include the come back of its former deputy leader Dolores Kelly in Upper Bann and the surprise success of Pat Catney in Lagan Valley thanks to Ulster Unionist transfers.

Media playback is unsupported on your device Media caption Watch: Mike Nesbitt announces he is resigning as UUP leader

The Ulster Unionist leader is among seven party leaders to be returned.

The others are First Minister and DUP leader Arlene Foster; Sinn Féin's northern leader Michelle O'Neill; Alliance Party leader Naomi Long; SDLP leader Colum Eastwood; TUV leader Jim Allister and Green Party leader Steven Agnew.

Image copyright Niall Carson Image caption Michelle O'Neill, Sinn Féin's Northern leader, celebrates winning her seat

DUP leader Arlene Foster declined several interview requests from the BBC. However, in her acceptance speech, she said the run-up to the election had been "challenging", but the focus was the future.

"Let us move forward with hope that the common good will be able to prevail over narrow divides of interest; hope that civility can return to our politics; hope that a functioning assembly can be restored and hope that a Northern Ireland with so many overlapping cultural identities can be home to all of us," she said.

Image copyright PA Image caption DUP leader Arlene Foster is re-elected in Fermanagh and South Tyrone

Four former ministers - two from the DUP, one from the SDLP and one from the Ulster Unionist party - lost their seats.

The first big shock of the day came when Alex Attwood, SDLP, lost his seat in Belfast West. The second was when Danny Kennedy, UUP, was eliminated in Newry & Armagh - he had been an assembly member since 1998.

Image copyright PAcemaker Image caption Alliance leader Naomi Long celebrates her success

Later, DUP stalwart Nelson McCausland lost his seat in Belfast North and his party chairman Lord Morrow lost his seat in Fermanagh and South Tyrone.

The SDLP suffered a body blow in Foyle - the traditional heartland of the party and former seat of its founder John Hume.

Sinn Féin came home first and second in the count, leaving the SDLP leader Colum Eastwood and Mark H Durkan trailing in their wake.

Media playback is unsupported on your device Media caption Former MLA Alex Atwood was eliminated in the 2017 count

The party, which once held sway in west Belfast, no longer has a presence there after Mr Attwood's defeat.

The election - the second in 10 months - was called after the collapse of a coalition led by Arlene Foster's DUP and Sinn Féin's Martin McGuinness.

Image caption Long-standing SDLP assembly member Alex Attwood failed to secure his seat in west Belfast

Mr McGuinness resigned over Mrs Foster's refusal to step aside as first minister pending an inquiry into the Renewable Heat Incentive (RHI) scheme, which could cost the Northern Ireland tax payer £490m.

SDLP leader Colum Eastwood said Sinn Féin were the "net beneficiaries" of a huge nationalist turnout intent on punishing Mrs Foster.

Image copyright Tony Hendron Image caption Danny Kennedy, UUP, prepares to speak to the media following his defeat

Former DUP Minister Jonathan Bell who was suspended from the party for allegedly speaking to the press without permission over the RHI scandal, has also lost his seat.

Under Northern Ireland's power-sharing agreement, the government must be run by Irish nationalists and unionists together.

Media playback is unsupported on your device Media caption Take a look at how BBC News NI has covered elections over the past 20 years

A total of 1,254,709 people were eligible to vote for 228 candidates competing for 90 seats in 18 constituencies. The turnout was up across the board.

Among the smaller parties, Gerry Carroll, People Before Profit Alliance, kept his Belfast West seat. However, his running mate Michael Collins was eliminated on the first count.

The largest unionist and nationalist parties after the election will have three weeks to form a power-sharing government to avoid devolved power returning to the British parliament at Westminster for the first time in a decade.

Image copyright Liam McBurney Image caption Sinn Féin's Niall O Donnghaile, DUP candidate Christopher Stalford and Alliance candidate Emmet McDonough-Brown at the Titanic Belfast count centre

The BBC News NI website will carry the latest election results and analysis on Friday and throughout the weekend.