The resolution, without naming any countries, says that surveillance and data interception by governments and companies "may violate or abuse human rights".
The US and key allies Britain, Australia, Canada and New Zealand joined a consensus vote passing the resolution after language which suggested that foreign spying would be a rights violation was weakened.
The resolution said the UN General Assembly's rights committee is "deeply concerned at the negative impact" that surveillance and interception of communications "including extraterritorial surveillance" can have on human rights.
Germany and Brazil had wanted the resolution to say the assembly was "deeply concerned at human rights violations and abuses that may result from the conduct of any surveillance of communications, including extraterritorial surveillance of communications."
Germany's Chancellor Angela Merkel and Brazil's President Dilma Rousseff have reacted with fury to reports that the US National Security Agency has spied on their phone calls and office communications.
Germany's UN ambassador Peter Wittig said that while the resolution is non-binding it was an important "political message".
Wittig stressed that it was the first time that the UN has said that "unlawful and arbitrary surveillance domestically and extra territorially might violate human rights".
The resolution will now go to the full 193-member UN General Assembly for a vote.