There was a collective intake of breath in Government Buildings yesterday when the Supreme Court delivered its judgment on an international trade agreement and instantly created a political and legal nightmare for the coalition.

The decision of the judges to uphold a Green Party TD's challenge to a pact between Canada and the EU means the ministers will have to have a long hard think about what to do next.

At the heart of the issue is that fact that Government has committed to ratify the trade agreement because Ireland is a European Union member state.

Part of the deal includes a system of arbitration that would allow disputes between the State and multinationals to be dealt with by a panel of experts instead of being heard by the Irish courts.

Green TD Patrick Costello raised concerns about this and took a High Court case arguing that such a system would be unconstitutional.

That was a highly unusual move because in effect he was taking a legal challenge against the coalition that included his own party.

He argued that if Ireland agreed to this new system of arbitration it should be put to voters in a referendum.

He lost his case in the High Court, but then appealed to the Supreme Court, where he won yesterday much to the surprise of ministers.

It was a majority decision by the judges who ruled four to three in his favour.

Politically this is a bloody nose for the coalition, which is made up of the Greens, Fianna Fáil and Fine Gael.

Patrick Costello had already been ousted from the Greens' parliamentary party earlier this year because he sided with Sinn Féin in opposition to the new National Maternity Hospital.

Patrick Costello challenged the EU-Canada trade deal

Mr Costello and another Green TD Neasa Hourigan are due to rejoin the parliamentary party next week after spending six months in the political wilderness.

As they do so the Canada-EU deal is back in the spotlight.

The trade parts of the agreement were implemented in 2017, but the other parts remain very controversial within the Greens and are still due to be approved by Ireland.

Before the party joined the coalition it was opposed to the trade agreement.

When it came to power Green Party leader Eamon Ryan accepted that the Government would have to agree to back the trade deal, but some members of the parliamentary party, including Patrick Costello, Neasa Hourigan and Senator Vincent P Martin, expressed reservations.

Many on the opposition benches, including Sinn Féin and the Social Democrats, are firmly against the agreement.

Now the Government plans to amend existing law to make the trade agreement constitutionally palatable.

That will make it a difficult political issue once again, particularly within the Green Party.

In particular, observers will be closely watching to see if Patrick Costello and Neasa Hourigan oppose the coalition again when it seeks introduce amendments to ratify the agreement.

Even if the pair oppose the deal, the Government is still likely to get it approved as the coalition has a working majority in the Dáil.

Business lobby group IBEC argues the entire trade agreement is economically important and it should be ratified.

Tánaiste Leo Varadkar, who has responsibility for enterprise, says the coalition remains committed to the deal.

But yesterday’s decision won’t have been welcomed by those in Government Buildings who were hoping the courts would make this problem go away.