The bill comes after more than two decades of effort from activists and politicians, after previous drafts did not reach parliament.
With the support of nearly all lawmakers in the upper house, the law next needs royal approval. It will come into force 120 days after it is published in the royal gazette.
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 territory 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, with some raising their fists in solidarity with the LGBT community.
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 Thavisin, 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.