Northern Ireland’s first minister, Arlene Foster, has seen off an attempt to remove her from office following a failed green energy scheme costing taxpayers £400m.

While 39 assembly members voted for the no-confidence motion versus 36 against, it was still defeated because in order to pass it needed the backing of a majority of nationalist and unionist members.

The Social Democratic and Labour party (SDLP) had won cross-party support from unionists, greens and leftwingers for its motion censuring Foster over allegations about the “cash for ash” scandal.

The motion of no confidence was supported by a majority of voting MLAs but was defeated because it did not secure the required level of cross-community support, due to the opposition of Foster’s Democratic Unionist party (DUP).

While the DUP’s partner in government Sinn Féin also called for Foster to stand down, its members did not vote in the debate. Instead it proposed its own motion on the scandal for mid-January. That move eased fears of an immediate threat to the political institutions, though the crisis is far from over.

In an acrimonious three-hour debate in the regional parliament, the Ulster Unionist party leader, Mike Nesbitt, said the scandal had reduced devolution to “collectively a laughing stock”.

All the main opposition parties – the Ulster Unionists, the Greens, Traditional Unionist Voice and the leftwing People Before Profit – had backed the SDLP’s move to exclude Foster from Northern Ireland’s highest office.

This latest crisis to imperil the power-sharing executive is related to the renewable heating incentive (RHI), a scheme set up in November 2012 to encourage the consumption of heat from renewable sources.

It offered huge and, its critics say, inflated financial incentives to farms, businesses and other non-domestic consumers to use biomass boilers that mostly burned wood pellets, as well as solar thermal and heat pumps.

A whistleblower in February this year alleged the scheme was being abused and that one farmer at least had actually made £1m out of renting an empty shed.

Northern Ireland’s auditor general, Kieran Donnelly, concluded this summer that there was “no upper limit on the amount of energy that would be paid for”.

In her 15-page statement to the regional parliament, which opposition parties boycotted by walking out, Foster admitted that it was the “biggest regret” of her political career that there was no cap put on huge payments to those who availed themselves of the energy scheme.

The DUP leader stressed that she did “not impose this scheme on the people of Northern Ireland”.

Foster told the more than half empty chamber that she did not receive any indication or any “warning signs” that controlling the cost of the scheme was an urgent priority.

Later Sinn Féin’s deputy first minister, Martin McGuinness, called on the other parties to back its alternative motion urging Foster to step aside while an independent inquiry was held.

“Today we have witnessed a shambles in the assembly. Our institutions should not have to endure another day like this,” McGuinness said.

Northern Ireland’s justice minister, Claire Sugden, an independent unionist assembly member, backed the DUP in the vote.

“I would kick the house of cards down myself if Northern Ireland didn’t have so much to lose,” Sugden said, adding that she said she not support the motion because it was premature.

Last week former Stormont minister Jonathan Bell accused fellow DUP members of delaying the closure of the scheme.

Bell also alleged that DUP advisers had tried “cleanse the record” of any links between Foster and the decision-making process that led to the RHI scheme’s creation.

The SDLP leader, Colum Eastwood, said the allegations of very serious wrongdoing were “the biggest public finance scandal in the history of devolution”.