By a majority of eight to three, the Supreme Court decided May could not use executive powers known as "royal prerogative" to invoke Article 50 of the EU's Lisbon Treaty and begin two years of divorce talks.
"The Supreme Court today rules that the government cannot trigger Article 50 without an act of parliament authorising it to do so," said Supreme Court President David Neuberger.
However, the judges did remove one major potential obstacle, saying May did not need the approval of the UK's devolved assemblies in Scotland, Wales and Northern Ireland before triggering Brexit.
May has said she intends to invoke Article 50 before the end of March but the ruling means she must bring legislation before parliament before she can go ahead.
That opens up the Brexit process to scrutiny from lawmakers, the majority of whom had wanted to stay in the EU. However, the main opposition Labour Party said it would not block Brexit although it would try to amend the legislation.
"Labour will seek to build in the principles of full, tariff-free access to the single market and maintenance of workers' rights and social and environmental protections," said party leader Jeremy Corbyn.
Attorney General Jeremy Wright, the government's top lawyer who argued its case, said ministers would implement the court's ruling.
"Of course the government is disappointed with the outcome," Wright said outside the Supreme Court. "The government will comply with the judgment of the court and do all that is necessary to implement it."
May said the decision did nothing to change the path of Brexit.
"The British people voted to leave the EU, and the government will deliver on their verdict - triggering Article 50, as planned, by the end of March," her spokesman said.
Last week May set out her stall for negotiations, promising a clean break with the world's largest trading bloc as part of a 12-point plan to focus on global free trade deals, setting a course for a so-called "hard Brexit".
Some investors and those who backed the "remain" campaign hope that lawmakers, most of whom wanted to stay in the EU, will force May to seek a deal which prioritises access to the European single market of 500 million people, or potentially even block Brexit altogether.
Sterling initially rose on the news that the government had lost its appeal, but it then fell over half a cent to hit day's lows against the dollar and euro after the ruling that the devolved assemblies did not need to give their assent. By 1022 GMT it had trimmed some of those losses and stood at $1.2485, down 0.4 percent on the day.
Enter a name and e-mail address and we will e-mail this website link too them.