SAN FRANCISCO—California's state legislature on Thursday passed the nation's first law banning professional psychological therapy aimed at turning gay and lesbian youth straight.

The legislation, which will next go to Gov. Jerry Brown for review, prevents licensed psychologists and therapists from seeking to change the sexual orientation of children under 18.

The...