MI5 has been unlawfully holding people's data collected through surveillance or hacking programmes, the high court has been told.

In a case brought by civil rights group Liberty, it emerged that MI5 has been holding large volumes of people’s location data, calls, messages and web browsing history without proper protections.

The security agency are also accused of misleading senior judges by applying for warrants on the basis that data protection obligations were being met - when in fact they were not.

The spy agency has been aware of breaches of compliance for at least three years, yet failed to act and, it is claimed, kept the failings secret.

They have now been exposed by the official watchdog, the investigatory powers commissioner, Lord Justice Fulford, and admitted in outline by Sajid Javid, the Home Secretary.

Liberty said it involved the "mass collection of data of innocent citizens." Megan Goulding, a lawyer for the civil rights group, said: "MI5 have been holding on to people's data - ordinary people's data, your data, my data - illegally for many years.

"Not only that, they've been trying to keep their really serious errors secret - secret from the security services watchdog, who's supposed to know about them, secret from the Home Office, secret from the prime minister and secret from the public."