An apparatus for packing products in cartons , comprising: - a first feed line for feeding cartons , - a second feed line for feeding products , synchronized with the first feed line in such a way that the products can be inserted into the cartons used to pack them, - a plurality of pushing elements movable one after the other in synchrony with the feed lines , - a diverting unit adapted to operate on the pushing elements in transit and switchable between a first configuration, in which the diverting unit directs the pushing elements along an active path where each pushing element is driven to push a product into a respective carton , and a second configuration in which the diverting unit directs the pushing elements along an inactive path , - detecting means for detecting parameters identifying the presence of the carton and/or of the product on which a certain pushing element must operate, the detecting means comprising at least one detecting sensor, - switching means connected to the detecting means and configured to switch the diverting unit to the first configuration or to the second configuration as a function of the identification parameters; characterized in that each pushing element comprises a first carriage configured to run on a first rail defining the active path and a second carriage configured to run on a second rail defining the inactive path , and in that the diverting unit comprises a first diverting rail and a second diverting rail adapted, respectively, to receive the first carriage of the pushing element in the first configuration and the second carriage of the pushing element in the second configuration, the first diverting rail defining a first stretch of the first rail of the apparatus in the first configuration and the second diverting rail defining a second stretch of the second rail in the second configuration. - a first feed line for feeding cartons , - a second feed line for feeding products , synchronized with the first feed line in such a way that the products can be inserted into the cartons used to pack them, - a plurality of pushing elements movable one after the other in synchrony with the feed lines , - a diverting unit adapted to operate on the pushing elements in transit and switchable between a first configuration, in which the diverting unit directs the pushing elements along an active path where each pushing element is driven to push a product into a respective carton , and a second configuration in which the diverting unit directs the pushing elements along an inactive path , - detecting means for detecting parameters identifying the presence of the carton and/or of the product on which a certain pushing element must operate, the detecting means comprising at least one detecting sensor, - switching means connected to the detecting means and configured to switch the diverting unit to the first configuration or to the second configuration as a function of the identification parameters; characterized in that each pushing element comprises a first carriage configured to run on a first rail defining the active path and a second carriage configured to run on a second rail defining the inactive path , and in that the diverting unit comprises a first diverting rail and a second diverting rail adapted, respectively, to receive the first carriage of the pushing element in the first configuration and the second carriage of the pushing element in the second configuration, the first diverting rail defining a first stretch of the first rail of the apparatus in the first configuration and the second diverting rail defining a second stretch of the second rail in the second configuration. <EOS>