A vote in favour of a system where people are presumed to have consented for their organs to be donated after death has been hailed as a "historic day" by Wales' health minister.
It means Wales will be the first UK nation to introduce a system where people are presumed to have consented to become donors unless they opt out.
It could come into force by 2015.
Mark Drakeford said he was proud about Tuesday's vote but his thoughts were with those waiting for organs.
The vote took place just before 22:00 BST and 43 of the 60 assembly members backed the bill. Eight Conservatives voted against and Welsh Conservative leader Andrew RT Davies did not vote. Plaid Cymru AM Jocelyn Davies abstained.
Mr Drakeford told BBC Wales the vote followed an "epic" five-hour discussion, adding: "I'm very relieved to see the bill safely on to the statute books but very proud as well - proud of achieving this in Wales, proud of the job that the assembly has done in scrutinising and improving the bill."
He said that "most of all, my feelings are with those people waiting for donation whose lives depend upon having an organ through transplantation".
The current system, which operates across the UK, relies on people signing up to a voluntary scheme and carrying a donor card.
But the Welsh government wants to drive up low transplant rates by 25% and say the new scheme will save countless lives.
As currently happens, organs could go to recipients anywhere in the UK, not just in Wales.
According to the NHS Blood and Transplant service, there are around 250 people on a waiting list for a transplant at any one time, and 33 people in Wales died in 2012/13 while waiting.
Evidence from other countries with an opt-out system indicates that the rise in organ donors is small with around 15 additional donors provided each year and approximately 45 extra organs.
There has been opposition to the scheme but ministers insist it will be implemented sensitively and they will launch a two-year, £8m publicity drive to inform people about their choices.
The British Medical Association (BMA), welcomed the result of the vote.
Dr Richard Lewis, BMA Wales secretary, said: "A few years ago, Wales was ready to lead the UK on banning smoking in public places but we didn't have the necessary legal powers.
"This time we are delighted that our National Assembly has shown the rest of the UK the way forward and fully support its implementation.
"Patients across the country will now benefit directly or indirectly from this bill."
Roy J Thomas, chief executive of Kidney Wales Foundation (KWF) said: "Deemed consent has a positive and sizeable effect on organ donation rates of some 25% to 35% higher on average in presumed consent countries.
"One person dies every week in Wales waiting for an organ transplant.
"Three people die a day in the UK. The current system has failed those waiting."
There had been opposition to the changes from Christian churches and from within the Muslim and Jewish communities, who wanted a "soft opt-out scheme" to give deceased patients' families a say on donation if their relative had neither opted in or out.