Ireland has lost a case in the EU's highest court over a European directive on the retention of data by telecoms and Internet providers.
The Data Retention Directive was agreed by EU member states in 2006.
It required Internet providers and telecommunications companies to hold on to data relating to emails and phone calls for a period of between six months and two years.
European companies had until then tended to erase such data after it had been used for billing purposes.
But following the 11 September attacks EU member states agreed that police forces across Europe should have access to such information for counter-terrorism reasons.
The directive was to give police access to data relating to the maker and recipient of phone calls and emails, as well as the time and duration involved.
It would not give police access to the content of the communications.
Ireland took a case to the European Court of Justice in Luxembourg on a technical issue.
The Government argued that the legislation should have been agreed under the EU's crime and judicial affairs pillar, which means each country has a veto and the European parliament could only be consulted.
However, the directive was agreed under the pillar governing the single EU market, which requires a qualified majority of member states, and the European Parliament has a bigger say in the matter through co-decision.
The directive was eventually agreed through single market rules.
The reason was that telecoms and Internet providers who sold services across the EU would not have to deal with 27 different legal systems when it came to the rules on retaining telecoms and Internet data.
In other words, it was an Internal Market and not a Police and Judicial Affairs issue.
The European Court of Justice ruled today that the directive had been drawn up under the correct legal framework.
The court argued that different rules among 27 member states on how companies should retain data would incur significant costs for those companies and hamper the running of the single market.
At present in Ireland, telecoms companies and Internet service providers must hold on to data for three years.