The legislation passed with 151 votes in the 199-member parliament, with 12 against and 27 abstentions.
The ruling center right Fidesz party of Prime Minister Viktor Orban was supported in the vote by radical nationalist Jobbik party, which previously sought even tougher measures.
Orban said on Monday that millions more refugees are expected to arrive in Europe, with no end in sight.
“Several hundred thousand have already arrived and we are expecting millions more. And we do not see where this ends. Many more millions want to embark on a journey [to Europe],” Orban told a session of the Hungarian parliament.
The prime minister listed Iraq, Syria, Somalia, Libya, Sudan and Afghanistan as the main countries from which around 10 million refugees could arrive.