Portugal's Constitutional Court has disallowed legislation that would have given intelligence agencies access to private communications metadata.

The judges declared the bill passed by Parliament last month illegal because it contravened article 34 of the Constitution, which forbids authorities' access to private communications unless they are part of a criminal investigation and sanctioned by a judge.

The court said in a ruling issued late Thursday that a planned oversight committee would not have the same level of control over data-gathering activities as a criminal court judge.

The three main parties in Parliament voted for the law, saying it was needed to help protect against acts of terror and international organized crime.

The law is expected to be redrawn by the government which takes office after October's general election.