Carmarthenshire County Council had approved a planning application for the scheme and the proposals had also received the approval of conservation advisor Natural Resources Wales and a planning inspector following a public inquiry.
The company's proposals included raising ground levels before building work started and it insisted that any risk of tidal flooding, even in the most extreme conditions, was miniscule.
However, ministers disagreed with the inspector and refused planning permission earlier this year.
Attacking the ministers' decision as "a terrible mistake" at the High Court, the company and the council claimed tidal maps which showed part of the site within the flood risk zone were inaccurate.
Relying on expert hydrological evidence, the company insisted that - with ground levels raised and even taking into account the potential impact of climate change - there was at most a 0.1 per cent chance of any of the site flooding in any one year.
Even if the worst happened in "extreme" tidal conditions, flood levels would only rise to a few inches and the benefits of the development greatly outweighed whatever small risk there might be, it was argued.
However, dismissing the challenge, Mr Justice Cranston said the ministers had been entitled to rely on the flood maps which classified parts of the site as falling within a "highly vulnerable" area without any significant flood defences to protect them.
The ministers had rightly adopted a "precautionary approach" to the flooding issue and there had been no unfairness to Castletown which had been given a "fair crack of the whip" in its fight for planning permission.