This paper describes an optimal torque vectoring strategy for 4WD electric vehicles (EV) in order to improve vehicle maneuverability, lateral stability and at the same time prevent vehicle rollover. The 4WD EV is driven using an in-line motor at a front driving shaft and in-wheel motors at rear wheels. Many previous studies have been conducted to determine a desired traction force and a yaw moment input for human driver's intention or vehicle stability control. The driving control algorithm consists of three parts: a supervisory controller that determines the control mode, admissible control region, and desired dynamics, such as the desired speed and yaw rate, an upper-level controller that computes the traction force input and yaw moment input to track the desired dynamics and an optimal torque vectoring algorithm that determines actuator commands, such as the front in-line motor, rear in-wheel motors and independent brake modules. The optimal torque vectoring algorithm is developed to map the desired traction force and the yaw moment input to the actuators, taking into account the actuator constraints. Also, a wheel slip controller is designed to keep the slip ratio at each wheel below a limit value. An optimization-based control allocation method is used to determine the actuator command in order to apply the desired traction force, the yaw moment input and the wheel slip control inputs to the test platform. Numerical simulation studies have been conducted to evaluate the proposed optimal torque vectoring algorithm. It has been shown from simulation studies that the vehicle maneuverability and vehicle stability can be improved by the proposed driving control algorithm.