The legislation also bans the use of agents, or any promotion of women willing to carry babies for others.
Last year the case of a little boy born with Down's syndrome put Thailand's surrogacy industry in the spotlight.
His Thai surrogate mother said his Australian parents abandoned the boy but took his healthy twin sister home.
Under the new law, only married Thai couples or couples with one Thai partner who have been married at least three years can seek surrogacy, and commercial surrogacy is banned.
Anyone caught hiring a surrogate mother faces a maximum jail sentence of 10 years.
Agents touting surrogate mothers would also face imprisonment if caught.
'Baby factory'
The case of the Australian boy - named "baby Gammy" - made headlines around the world after his Australian parents took his healthy twin sister home and left him in Thailand.
He remained with surrogate mother Pattaramon Chanbua, 21, and was later granted Australian citizenship so he can have access to medical care.
Concern about the industry worsened when a Japanese man was found to have fathered more than a dozen babies by different Thai surrogates, a case later dubbed "the baby factory".
Analysis: Jonathan Head, South Asia correspondent
It has been nearly five years since Thailand began drafting a law on commercial surrogacy. The bill had been stalled by successive political crises, but the plight of Baby Gammy, and then the shocking revelation of Mitsutoki Shigeta's 16 or more surrogate babies, spurred the Thai government into action. They were shamed by the moniker 'Womb of Asia' that Thailand had earned from its booming surrogate business.
The yearning of childless couples for babies will now probably move on to less regulated countries. But will surrogacy end in Thailand? The money to be made is so tempting for poor families that the business may still survive as an underground, illegal one, with all the dangers to the women of exploitation and poor health facilities.
Law enforcement in Thailand is famously lax. And there is still a debate over whether legitimate surrogates should be paid something for the time, effort and health risks they take in carrying some else's baby.