The regime under which listening post GCHQ carries out hacking of suspects' computers and smartphones does not breach human rights laws, a tribunal has ruled.
ampaign group Privacy International and seven internet service providers mounted a legal challenge over activity known as equipment interference.
However, the Investigatory Powers Tribunal found in favour of the agency and the Foreign Office on all points of law in a judgment issued on Friday.
The use of equipment Interference, which is also referred to as computer network exploitation, by intelligence services was first disclosed last year.
It allows authorities to interfere with electronic devices such as smartphones, tablets and PCs in order to obtain data.
Operations can range from using a target's login credentials to gain access to information held on a computer to more sophisticated tactics such as remotely installing a piece of software in order to obtain the desired intelligence and covertly downloading the contents of a mobile phone.
In its judgment the tribunal, which considers complaints about the way public authorities use covert techniques, examined 10 issues relating to GCHQ's work.
It concluded that the legal regime under which warrants are issued for the agency to carry out equipment interference in the UK is compatible with European Convention on Human Rights articles.
The framework was also found to be compliant prior to the publication of a code of practice on the tactics in February last year.
In relation to authorisation of actions outside Britain, it said there might be circumstances in which an individual claimant might be able to claim a breach under articles 8 or 10 of the convention, which relate to the right to private and family life and freedom of expression.
However, it said that "does not lead to a conclusion" that the regime is non-compliant with the articles.
The tribunal also said it was "satisfied that the requirements for records are sufficient and satisfactory, and that adequate safeguards have been in place at all times for the protection of the product of CNE, and that there exists a satisfactory system of oversight".
Equipment interference features in the Government's draft Investigatory Powers Bill.
The judgment concluded: "The use of CNE by GCHQ, now avowed, has obviously raised a number of serious questions, which we have done our best to resolve in this judgment.
"Plainly it again emphasises the requirement for a balance to be drawn between the urgent need of the Intelligence Agencies to safeguard the public and the protection of an individual's privacy and/or freedom of expression.
"We are satisfied that with the new EI Code, and whatever the outcome of Parliamentary consideration of the IP Bill, a proper balance is being struck in regard to the matters we have been asked to consider."
The Foreign Office said the ruling made clear that the legal regime under which GCHQ carries out equipment interference "is, and has always been, compatible with human rights law".
Foreign Secretary Philip Hammond welcomed the ruling "and its judgment that a proper balance is being struck between the need to keep Britain safe and the protection of individuals' privacy".
He added: "The ability to exploit computer networks plays a crucial part in our ability to protect the British public.
"Once again, the law and practice around our security and intelligence agencies' capabilities and procedures have been scrutinised by an independent body and been confirmed to be lawful and proportionate."