The vote, one of the most divisive in Sweden in recent years, had initially been scheduled for early Wednesday but was postponed after more than one-third of MPs voted to send the bill back to parliament's defence committee "for further preparation."
After the committee required that the centre-right government safeguard individual rights further in an annex to the law to be voted on in the autumn, the bill narrowly passed with 143 votes in favour, 138 opposed and one parliamentarian abstaining.
Critics have slammed the proposal as an attack on civil liberties that would create a "big brother" state, while supporters say it is necessary to protect the country from foreign threats.
The new law, set to take effect on January 1st, 2009, will enable the National Defence Radio Establishment (FRA) -- a civilian agency despite its name -- to tap all cross-border Internet and telephone communication.
But although the government said only cross-border communications would be monitored, all communications risk getting caught in the net since some internet servers are located abroad and FRA would need to check all emails to determine whether they have crossed the border.
Under the current law, FRA is only allowed to monitor military radio communications.
The Defence Ministry, which hammered out the proposal, insists the new legislation is necessary in today's changed world, where communications are increasingly transmitted through fibre-optic cables.
The government holds a slim seven-seat majority in parliament, and with the left-wing opposition vehemently opposed to the proposal, just four "no" votes within the coalition could have sunk it.
A number of the coalition members had voiced deep concern about the bill before Wednesday's revision was made, while opponents in parliament, along with hundreds of demonstrators gathered outside the building, faced a nervy wait for the result.
"This law is rotten to the core. (It) is about violating integrity. Regardless of what words they use, it will do exactly that," one of the demonstrators, 32-year-old Magdalena Berg from Gothenburg, told Swedish public radio.
Critics of the new law, including human rights activists, journalists, lawyers and even the former head of the Swedish intelligence agency Säpo, had before Wednesday's revision argued that it did not go far enough in safeguarding individual rights.
Story continues below…
Unlike police, FRA will, for instance, not be required to seek a court order to begin surveillance.
The government on Wednesday insisted it had addressed these concerns with the last-minute revisions to the law that among other things added further independent and parliamentary controls to FRA's work.
Former Säpo chief Anders Eriksson, who currently heads up the Swedish Commission on Security and Integrity Protection, was not impressed.
"I think the law needs to be re-written. It is not enough to create a few checks and balances ... It is the law itself there is something wrong with," he told Swedish radio before the vote.