Lagrangian approach to the semirelativistic electron dynamics in the mean-field approximation