The bill, the culmination of more than two decades of effort by activists, was supported by an overwhelming majority of lawmakers in the upper house.
The law, which needs royal approval, will come into force 120 days after it is published in the royal gazette, meaning the first same sex weddings could take place later this year.
"Today we celebrate another significant milestone in the journey of our Equal Marriage Bill," Thai Prime Minister Srettha Thavisin said in a post on X.
"We will continue our fight for social rights for all people regardless of their status."
LGBT advocates called the move a "monumental step forward," as Thailand would be the first nation in Southeast Asia to enact marriage equality legislation and the third in Asia, after Nepal and Taiwan.
"We are very proud to make history," said Plaifah Kyoka Shodladd, member of a parliamentary committee on same-sex marriage.
"Today love triumphed prejudice ... after fighting for more than 20 years, today we can say that this country has marriage equality."
Lawmakers and activists were seen celebrating in Thailand's parliament, waving rainbow flags and smiling, and some raising their fists in solidarity with the LGBT community.
In Thailand's northern Chiang Mai province, human rights activist Matcha Phornin, her wife Veerawan Wanna and their adopted daughter were glued to their television screen as they watched the senate proceedings.
"We have support from the parliament, from the senators who passed this law. That means we are protected by law," said Matcha, after they cheered and hugged each other when the bill passed.
"And she will be legally adopted after this," Matcha said, referring to their daughter.
Thailand, one of Asia's most popular tourist destinations, is already known for its vibrant LGBT culture and tolerance.
At the start of June, thousands of revellers and activists paraded through the streets of Bangkok and were joined by Prime Minister Srettha, who wore a rainbow shirt to celebrate Pride Month.
"This would underscore Thailand's leadership in the region in promoting human rights and gender equality," the Civil Society Commission of marriage equality, activists and LGBTQI couples said in a statement.