Media playback is unsupported on your device Media caption Mrs Foster denounced the no-confidence motion as a 'coup d'état more worthy of a Carry On film'

A vote of no confidence in Northern Ireland's First Minister, Arlene Foster, has been defeated in the assembly.

Stormont's political institutions are under threat of a meltdown in a row over a botched heating scheme.

Members of the assembly walked out of the chamber twice on Monday morning.

However, Deputy First Minister Martin McGuinness said Sinn Féin - partners in government with the DUP - would not be pulling the plug on Stormont.

In an interview with the BBC, he said: "We are dealing with a shambles and there is an urgent need to restore credibility in the institutions.

"It's very, very important that the executive office finds a way forward through the quite clear difficulties," he said.

He said his party will put forward a motion in the assembly calling for an investigation into the "debacle" and urge the first minister to step aside during an investigation into the scheme.

Earlier, Mrs Foster said she would resist her opponents' "fevered quest" to build her "political gallows".

She exclaimed "trial by television" as she faced a no-confidence vote over the botched Renewable Heat Incentive Scheme (RHI) that could cost taxpayers £400m.

In an interview with the BBC's Stephen Nolan on Thursday, Jonathan Bell, a former enterprise minister, broke ranks with his DUP colleagues and made a number of sensational claims about how the controversial scheme was handled.

The RHI was set up by the Department of Enterprise, Trade and Investment (Deti) under the stewardship of Mrs Foster in 2012 to encourage businesses and other non-domestic users to move from using fossil fuels to renewable heating systems.

But flaws in setting the scheme's subsidy rate left it open to abuse as claimants could earn more cash the more fuel they burned.

The scheme was finally halted early this year, by which time its overall cost had reached £1.18bn.

About £20m a year for the next two decades could be taken from the Northern Ireland budget to cover the overspend.

"They can't gang up and kick out the elected leader of unionism," Mrs Foster told the Northern Ireland Assembly.

"I am here and I will be staying here," she said. "I have acted with the highest level of integrity."

Media playback is unsupported on your device Media caption MLAs walked out as Mrs Foster began her statement on Monday

She also treated her political opponents in the SDLP, Ulster Unionists, Alliance and TUV, to a razor-sharp tongue lashing. The gloves were off.

She said she was "glad" that Colum Eastwood, SDLP, and Mike Nesbitt, UUP, "aren't very good" at opposition.

The Alliance Party had, in the past, acted in a more "considered and responsible way", she said, "but that was under a different leader".

"No doubt, at some point, we will hear today this decision is related to the flags protest," she said.

Mrs Foster said the motion to bring her down was "doomed" and that this was a "coup d'état more worthy of a Carry On Film".

While 39 assembly members voted for the no-confidence motion and 36 against, it was still defeated because Assembly votes require a majority of unionists and nationalists to back any motion.

Sinn Fein members were not present in the chamber for the vote.

Earlier, a series of stormy arguments and walk-outs threatened to lurch Northern Ireland into a fresh constitutional crisis.

Image copyright PA Image caption Sinn Féin wants Arlene Foster to step aside while an independent investigation is held into the scandal

The row that erupted in the assembly on Monday was over Mrs Foster's decision to "fly solo" .

She prepared to make a ministerial statement without the support of the Deputy First Minister Martin McGuinness, Sinn Féin, with whom she shares the joint office.

Analysis - BBC News NI political correspondent Enda McClafferty

When it works, it shows politics in Northern Ireland is moving in the right direction but when it goes wrong it reopens old wounds and leaves the institutions hanging by a thread.

Joint ministerial authority means Arlene Foster and Martin McGuinness have equal power and cannot work in isolation. They have no choice.

That's why Arlene Foster's decision to make a statement without the support of her partner in office today has plunged Stormont into a fresh crisis.

Joint office is the bond which holds Stormont together, it now appears to be melting fast in this heating scandal.

The other parties walked out of the chamber and stormed to the press microphones to voice their anger.

Mr McGuinness made it clear that Mrs Foster did not speak for him or with him. He said she would be acting without his approval or authority.

Earlier, he had warned that a DUP-established inquiry into the so-called "cash for ash" affair would have no credibility.

He also said that there would be grave consequences if the DUP took a unilateral approach and Mrs Foster made a ministerial statement without his support.

Media playback is unsupported on your device Media caption RHI scandal: Bell claims DUP advisers 'interfered in closure'

Speaker Robin Newton, DUP, found himself at the eye of the storm, facing a barrage from politicians over the right of Mrs Foster to make the statement without the support of her deputy first minister.

But he went ahead and called on Mrs Foster to speak.

She ended up preaching to the converted as nearly all of the MLAs from the other parties left the chamber again.

Her DUP colleagues heard her say that not introducing cost-control measures in a botched heating scheme was the "greatest political regret of my life".

It was not clear whether she was speaking in her capacity as first minister or whether it was personal.

Image caption Mr Hamilton said the allegations made by Mr Bell were serious and warranted investigation

The DUP accused the other parties of "running away" when they left the chamber and Mrs Foster asked: "Where are they? The people of Northern Ireland deserve better than this."

The other parties rolled their eyes.

Eamonn McCann, People Before Profit, said there was "no shortage of clowns but no ring master" at Stormont.

"We are now in La La land and limbo land," he said.

TUV leader Jim Allister said: "I know it's pantomime season but what has happened today is beyond farce."