Parliament's unelected upper chamber on Friday voted in favour of the legislation, which was passed two days earlier by the elected House of Commons.
The bill, which would compel Johnson to seek a three-month delay to Brexit if he does not manage to strike a deal with the EU by 19 October, will now go for formal approval by Queen Elizabeth II.
It will become law within days once it gets the formality of royal assent.
- British MPs vote to block no-deal Brexit, scupper PM's call for snap election
- Johnson loses control of UK parliament as MPs force vote on Brexit delay
Johnson says the UK must leave the bloc on the currently scheduled date of 31 October, even if there is no deal. But earlier this week he lost his parliamentary majority and expelled 21 lawmakers from his ruling Conservative Party's group in parliament after they supported an opposition plan to try to bloc a no-deal exit.
Johnson says the only solution is a new election, which he wants to take place on 15 October, allowing him to win a new mandate with two weeks left to leave the bloc on time.
But opposition parties, including the Labour Party, said they would either vote against or abstain on calls for an election until the law to force Johnson to seek a Brexit delay is implemented.
Johnson failed in his first bid to hold snap elections on Wednesday.
Opposition lawmakers are wary of approving an election, which would mean the dissolution of parliament. MPs want to ensure they can still sit in October to ensure Johnson complies with the law requiring he delay Brexit.
'Rather die in a ditch'
Leading Leave campaigner Johnson said he would rather "die in a ditch" than delay Brexit.
He says he wants a deal with Brussels but would be willing to leave without one, and has cast the bill aiming to stop a no-deal Brexit as a surrender to the EU.
"I'll go to Brussels, I'll get a deal andlords we'll make sure we come out on October 31, that's what we've got to do," Johnson said Friday during a visit to a farm in Scotland.
When asked if he would resign if he could not deliver, he said: "That is not a hypothesis I'm willing to contemplate."