SAN FRANCISCO—California’s Assembly voted to approve a sanctuary bill Friday afternoon, moving the state significantly closer to impeding the Trump administration’s efforts to deport illegal immigrants.

The bill, which limits local law enforcement cooperation with federal officials, passed 50 to 26. It now moves back to the state Senate for a final vote, then to Gov. Jerry Brown.

The bill’s author, Democratic State Senate President Kevin de León, and Mr. Brown negotiated for several weeks, coming to an agreement on a final bill just days before the state’s legislative deadline loomed. Mr. Brown sought more-limited protections for immigrants than Mr. de León had wanted.

The maneuvering shows the deep political divisions over immigration as states struggle to set their own policies—even in California, a Democrat-majority state which offers an array of benefits to undocumented immigrants.

Texas passed a law banning sanctuary cities, setting off suits and countersuits within the state. A federal judge has temporarily blocked the law.