This paper deals with the use of grid-connected photovoltaic (PV) power plants for supplying the ancillary service of reactive power compensation to the distribution grid. A control strategy has been developed for controlling both real and reactive power exchanged with the distribution network. The paper suggests how the real and reactive power references should be selected in order to maximize the electrical energy generated by PV arrays and to exploit the apparent power of the inverter close to its rated value. The choice suggested for reference signals allows reactive power compensation service also when the solar irradiation is negligible. The control strategy is then applied to a sample grid-connected PV unit, which has been simulated in Simulink environment. Numerical simulations show that, using an adaptive Perturb & Observe algorithm, the maximum power point tracking is achieved in about 2 seconds, both at starting and when the irradiation changes. The inverter is also capable of giving without interruptions the reactive power support to the grid, reducing grid currents and voltage drops along the line respect to the classical configuration where no reactive compensation is present