An active implantable medical device for cardiac resynchronization with automatic optimization of atrioventricular and interventricular delays is disclosed. The device collects an endocardial acceleration signal EA and calculates the atrioventricular delay AVD and the interventricular delay VVD. The device isolate in the EA signal a component EA4 corresponding to the fourth EA peak and measure a temporal parameter related to a time interval between the detection of an atrial event (P/A) and the occurrence of the EA4 component. The device isolates an EA1 component corresponding to the first EA peak and measures a non-temporal parameter (APEA1) related to the peak amplitude or a signal energy of the EA1 component. The optimal AVD (AVDO) is determined by the temporal parameter related to the EA4 component, and is calculated for a plurality of different values of VVD to obtain a plurality of pairs of optimal values {AVDO, VVD}. The device selects one of these pairs of values based on the non-temporal parameter related to the EA1 component.