After 15 hours of heated debate, the parliament passed the 'Prevention of Terrorism Bill' with 79 votes in favour and 60 against it.
The bill that revived detention without trial will allow those involved or commissioned to carry out terrorist acts to be detained for years and have their movements restricted.
Members of the ruling Barisan Nasional (BN) coalition vociferously defended the necessity of preventive measures to deal with "extraordinary" threats posed by terror entities such as the Islamic State (IS).
They compared it to the harsh Internal Security Act which was repealed in 2012.
More From This Section
The decision came hours after authorities arrested 17 people who were planning terror strikes in the country.
Police said they had planned to kidnap high-profile figures in a bid to create an Islamic State-like regime in the country.
"We received information that they were also planning to raid several army camps and police stations to boost their weapons cache," Inspector-General of Police Khalid Abu Bakar said.
Earlier, Deputy Home Minister Wan Junaidi Jaafar told reporters that the arrests of the 17 Malaysians, including two who had just returned from Syria, showed that the law was needed and would prevent things from happening rather than wait for things to happen.
Dozens of government critics have been hit with sedition or other charges after criticising the regime.
Ruling party members said the law had enough provisions to safeguard the rights of everyone.
Opposition member N Surendran questioned the need for a two-year detention period without trial as countries with bigger threats such as the UK and the US had shorter detention periods.