The chance of Britain quitting the European Union will depend on the outcome of next month’s general election. But judging the risk is complex given the probable involvement of the Scottish National Party and the Liberal Democrats in supporting a government led by either Labour or the Conservatives.

If the UK’s two-party system was still intact, the analysis would be fairly simple. If he is re-elected, David Cameron, the prime minister and Conservative leader, has promised to renegotiate Britain’s relationship with the EU and then give the people a vote on whether to stay in.

Ed Miliband, the Labour leader, is opposed to such a referendum unless there is a transfer of power from Britain to Brussels, which is unlikely in the next few years. If it was a straightforward two-horse race, the risk of Britain leaving the EU would be basically a product of the chance of the Conservatives being re-elected and of the British people then voting to pull the country out of the EU.

However, the opinion polls are indicating that the Conservatives and Labour are neck and neck, and an outright win by either Cameron or Miliband is unlikely.

Several outcomes are possible. There could be a Labour government supported by the SNP, which will probably have the third-largest group of MPs. A Labour government could be kept in power by the Liberal Democrats, which is likely to have the fourth-largest grouping.

Alternatively, the Lib Dems might prop up a Conservative government. It is also quite possible that neither Labour nor the Conservatives can form a government and a second election needs to be called. The SNP has said it won’t back the Conservatives.

The scenario that poses no immediate risk to the UK’s continued membership of the EU is a Labour/Lib Dem coalition. Even that won’t put the issue to bed forever because the Conservatives would remain committed to a referendum if and when they get back into power.

A Conservative-led government supported by the Lib Dems would bring higher risk. Although the Conservatives’ current coalition partner is in favour of Britain’s EU membership and is opposed to a referendum, it would have to agree to one if it renewed its support for Cameron.

But that wouldn’t be the end of the matter because the Lib Dems should be in a position to extract concessions from the Conservatives to maximise the chances that Britain would vote in favour of staying in the EU.

The Lib Dems may insist that the question put to the electorate is something like “Do you want Britain to stay in the EU?” rather than “Do you want Britain to leave the EU?” This would mean those campaigning to keep the UK in the EU would be pushing for a “yes” vote rather than a “no” one – which would probably be to their advantage.

Second, the Conservatives’ putative Lib Dem partners may ask for 16- and 17-year-olds to be allowed to vote in the referendum. This again could be beneficial for the “in” campaign as the young are more pro-EU than older people.

Finally, the Lib Dems may insist on being involved in the renegotiation of Britain’s relationship with the EU. They will fear that the Conservatives will make impossible demands on Britain’s EU partners, provoking a failed renegotiation that could be exploited by those who want to pull the UK out of the EU.

The Lib Dems would have a reasonable chance of securing these concessions because Cameron himself wants to keep Britain in the EU, even though there are many eurosceptics in his party.

It may be thought that this is all that needs to be said about the risk of EU exit. After all, there is no danger of an immediate EU referendum if Miliband wins the election, as neither he nor any of his possible partners want a plebiscite.

While this is true, a Labour government propped up by the SNP may be unstable. There’s no chance of a formal coalition, not least because Miliband has said he won’t do deals with the Scottish party. Although the SNP may support Labour on a case-by-case basis, it is hard to see how such an arrangement could last a full five years. The SNP’s main goal is independence for Scotland, something Labour opposes. The SNP would at some point probably pull the rug from under Miliband’s feet, forcing a second general election.

Such a scenario would bring back the risk of exit, with a twist. This is because a second election wouldn’t be a re-run of next month’s vote. In the meantime, Cameron would almost certainly have been replaced as Conservative leader and there is a chance that the new boss will have had to take a eurosceptic line in order to win the backing of the party. If the Conservatives then won a second election, Britain could be heading for a confrontation with its EU partners which would ultimately lead to a departure.

There is a similar risk if next month’s election leads to a dead heat and a new election has to be called. The chance of this scenario has risen since Nick Clegg, the Lib Dem leader, said he would not join forces with Labour if it also needed the support of the SNP.

Exiting the EU would be bad for Britain and its partners. It would divide Europe both economically and diplomatically. The risk may reduce as the election results pour in on the night of May 7. In virtually all outcomes, however, the risk is likely to become more complex.