We employ quantum optimal control theory to realize quantum gates for two protected superconducting circuits: the heavy-fluxonium qubit and the 0-π qubit. Utilizing automatic differentiation facilitates the simultaneous inclusion of multiple optimization targets, allowing one to obtain high-fidelity gates with realistic pulse shapes. For both qubits, disjoint support of low-lying wave functions prevents direct population transfer between the computational-basis states. Instead, optimal control favors dynamics involving higher-lying levels, effectively lifting the protection for a fraction of the gate duration. For the 0-π qubit, offset-charge dependence of matrix elements among higher levels poses an additional challenge for gate protocols. To mitigate this issue, we randomize the offset charge during the optimization process, steering the system towards pulse shapes insensitive to charge variations. Closed-system fidelities obtained are 99% or higher, and show slight reductions in open-system simulations.