SAN FRANCISCO — The California Supreme Court granted a law license Thursday to a man who has lived in the U.S. illegally for two decades, a ruling that advocates hope will open the door to millions of immigrants seeking to enter other professions such as medicine, accounting and teaching.

The unanimous decision means Sergio Garcia, who attended law school and passed the state bar exam while working in a grocery store and on farms, can begin practicing law immediately.