The law was adopted after three days of debate by 174 members of parliament with ten abstentions and no votes against, according to an AFP tally.
The president of the assembly, Mohamed Ennaceur, called the passing of the law an "historic" moment and said it would "reassure" the nation's citizens.
The new legislation comes after a gunman massacred 38 tourists on a Tunisian beach in an attack claimed by Islamic State (IS) on June 26.
In March an attack on the Bardo museum in the capital Tunis that was also claimed by IS left 21 tourists dead.
While the law was widely supported by both secular and Islamist parties, it was strongly criticised by civil society and NGOs.
Critics condemned the fact the law brings back capital punishment for a number of offences, after a de facto quarter-century moratorium on executions.
They also questioned the powers the law accords the authorities, allowing them to detain suspects for 15 days without access to a lawyer or being brought before a judge.
The bill would also make it easier for investigators to use phone-tapping against suspects and make public expressions of support for terrorism a jailable offence.
Describing it as draconian, advocacy groups have said the law's definition of terrorist crimes is too vague and it fails to adequately safeguard the rights of defendants and could undermine freedoms.