According to media reports, the law managed to get pushed through by only one vote, in a 73-72 vote result, with the support of crossbench MPs Tony Windsor, Craig Thomson, Bob Katter and Andrew Wilkie, in the lower house.
Under the new rules, which will now move to Senate for clearance, employers have to conduct labour market testing and prove they searched for Australian workers before hiring temporary workers from overseas on 457 visas.
The government said there was widespread recruiting at the expense of Australian jobs.
Gillard had been making crackdown on 457 visas as one of the key elements of her campaign agenda.
More From This Section
However, business groups and the coalition accused Gillard of using inflammatory language as she campaigned earlier this year to ensure foreign workers did not push Australians to the back of the jobs queue.
In a bid secure support from crossbench MPs, the government agreed to amendments making clear employers must advertise in a newspaper for local workers up to four months before applying to hire people under the 457 scheme.
Unions have welcomed the passage of the law, which also extend the time by which 457 visa holders have to find another job if they are sacked.
"Its an important step forward in protecting the job security of Australian workers and also provides some more protection for workers who are here on 457 visas," Dave Noonan, construction division national secretary for the Construction Forestry Mining and Energy Union, said in a report in The Age.