This paper presents a new control algorithm for a three-phase four-wire active power filter (APF) to eliminate harmonies, to compensate reactive power and neutral currents and to balance load currents of mixing single-phase and three-phase diode rectifier under non-ideal mains voltage conditions. Three-phase four-wire APF is composed of a conventional three-leg voltage-source inverter (VSI) and split dc link capacitors with a hysteresis-band PWM current controller. MATLAB/SIMULINK power system toolbox is used to simulate the proposed system. The proposed method's performance is compared with conventional instantaneous power (p-q) theory. The simulation results are presented and discussed showing the effectiveness of the control algorithm. The proposed control algorithm is found quite satisfactory to compensate reactive power and neutral current while eliminating harmonics with load balancing under non-ideal mains voltage conditions.