After 61 hours of discussion, the legislation, which was slammed by the left as too tough and the right as too soft, was approved late Sunday by 228 votes in favour to 139 against.
Fourteen members of Macron's centrist Republic on the Move (LREM) party were among the 24 MPs who abstained, and one dissident quit the LREM parliamentary group after joining the naysayers - a rare display of defiance in the usually on-message movement. Jean-Michel Clement, a former member of the Socialist Party who joined Macron's party last year, said he had voted with his "conscience". Opposition was strongest on the right, with the conservative Republicans and far-right National Front (FN) leading a failed charge for much tougher controls on immigration.
FN leader Marine Le Pen, who won 36 percent of the vote in last year's presidential election run-off, said the law would lead to a "flood of migration". But NGOs were also up in arms.
Within minutes of the vote Amnesty International France issued a statement warning that the "dangerous" legislation, which allows for failed asylum-seekers to be detained for up to 90 days, jeopardised migrants' rights.
The French migrant-support charity Cimade was also sharply critical of the draft law.
"So men, women and children can be locked up for three months without committing an offence. No government has ever gone so far on locking up foreigners," it tweeted.
But opinion polls show voters supporting stricter rules, which the government presented as necessary to check the rise of populists who are on the march across Europe.
On Saturday, far-right activists from various European countries blocked a key mountain pass on the border with Italy to try prevent migrants - mostly young men from west Africa - crossing.
France received a record 100,000 asylum applications last year, bucking the general trend in Europe where the number of asylum seekers halved between 2016 and 2017.
MPs spent the weekend haggling over more than 1,000 proposed amendments to the bill, which aims to both improve conditions for asylum-seekers by halving the waiting time for a response to six months, and get tougher with those deemed "economic" migrants.
Leftwing opponents lashed out at measures to keep asylum seekers in detention.
"Nothing justifies locking up a kid," said Socialist deputy Herve Saulignac.
Leftist critics had also complained about plans to cut the time within which asylum-claimers can appeal if rejected for refugee status from four weeks to two, saying they would not have enough time to defend their claim.
They also came out against a proposed "solidarity offence" targeting people who assist border-jumpers, like farmer Cedric Herrou, a farmer who was given a suspended sentence for helping migrants cross into France from Italy.
The government eventually agreed to exempt anyone providing struggling newcomers with food, accommodation, medical, linguistic, legal or social assistance.
Among the measures that received broad support on the centre and left were plans to help refugees better integrate, with more free French lessons and the right to work after being in France for six months.
Despite the fractious debate, the bill was never really in jeopardy, thanks to Macron's large parliamentary majority. It now moves to the Senate.
The horse-trading in the National Assembly came as Macron's reform of the public sector runs into stiff opposition from trade unions and students, who have conducted weeks of strikes, demonstrations and sit-ins.
Rail workers object to plans to strip new recruits of jobs-for-life and early retirement while students have occupied some universities over new requirements for admission to public universities.
The unions are gambling on the resistance swelling into a mass movement but opinion polls suggest the opposite is happening, with just 43 percent backing the strike in an Ifop survey released Sunday and train strikes starting to ease.