MPs approved Cooper's bill at first reading by 312 votes to 311, a majority of just one. At second reading it passed with a majority of five by 315 to 310. At the final reading it passed again by just one vote with 313 for and 312 against.
During the votes yesterday MPs delivered a first tie in a Commons vote since 1993 as a proposal to allow a third round of indicative votes on Brexit alternatives was rejected.
They voted by 310 to 310 on Labour MP Hilary Benn's amendment, with Speaker John Bercow casting his vote, in line with precedent, with the noes. This meant Benn's amendment was defeated by 311 votes to 310, majority one.
A Government spokesman said it was disappointed that MPs had chosen to back the bill and that it would place severe restrictions on the Government's ability to negotiate an extension.
Earlier, May appeared to be moving towards Jeremy Corbyn's soft Brexit demands as her top law officer claimed a customs union with the EU would not be "a sell-out".
As May was holding "constructive" talks with the Labour leader over a cross-party deal, Geoffrey Cox, the Attorney-General, was sent onto the airwaves to make it clear that Tory "red lines" would have to move.
UK diplomats are already preparing to send a letter to the EU requesting a long Brexit extension, well ahead of the deadline of the European Council summit next Thursday.
Cox prompted open warfare in the Conservative Party as furious backbenchers demanded May's head, two junior ministers resigned, and the Prime Minister was braced for the possibility of Cabinet-level resignations to come.
Brexiteers warned May that agreeing to a customs union or any deal with Corbyn would be a "disaster" and a "betrayal" that would tear the Tory party in two. But an unrepentant May blamed hardline Eurosceptics for pushing her into a corner, saying their decision to vote against her deal three times meant a pact with Labour was now "the only way" to leave the EU in an "orderly" way.
Corbyn faced his own backlash over the talks with May, as Labour supporters warned against accepting any deal that did not include a second referendum and the continuation of freedom of movement. Talks between the two will continue tomorrow.
May appointed a Remain-heavy negotiating team to carry on the talks with Labour until her next meeting with Corbyn. Cabinet Office Minister David Lidington, Chief Whip Julian Smith and chief of staff Gavin Barwell all voted Remain, with only Brexit Secretary Steve Barclay voting Leave among the quartet.
May's Brexit negotiator Olly Robbins was in Parliament on Wednesday and was understood to be party to the talks.
If May fails to reach an agreement with Corbyn, she is expected to table a series of votes that will force MPs to choose between her deal or an alternative such as a customs union, which could take place on Tuesday.
The Government's letter to the EU requesting a long Brexit extension, which was not submitted today but was said by EU sources to be under active consideration, is understood to be designed to avoid Parliament taking control of the extension process via the bill that was debated today. The bill cannot become law until it passes through the House of Lords, which could happen as early as tomorrow.
Whitehall sources indicated that the Prime Minister has already made up her mind to request a long extension which will 'fall away' if and when the Withdrawal Agreement is passed in the Commons.
A long extension, or 'flextension', will still require the UK to continue with preparations for EU elections on May 23 - but these polls would no longer be required to be held if a deal was passed and ratified by May 22.
Mark Carney, the Governor of the Bank of England, said the risk of a "disorderly" no-deal Brexit was still "alarmingly high" because the EU could refuse an extension.
Cox set alarm bells ringing among Tory Eurosceptics by telling the BBC that "a customs union is not some kind of sell-out."
He said: "The only way, unless the Prime Minister's deal is to be voted through, is to seek with Labour some common ground, so that we can affect a swift exit.
"If we were not to leave because we were unprepared to move any of the red lines that we have set then it would effectively mean that we never leave at all.
"Even if there were a customs union...we would still repatriate a vast swathe of powers back to this country...so we really must get this into proportion. What is important is that we leave."