Jude Bellingham, Kylian Mbappe and Federico Valverde were on target for the Spanish giants, while Aboubakary Koita and Stavros Pilios scored for the Greek side.
Playing at home in Greece, AEK Athens took an early lead through Koita in the 12th minute. However, Bellingham restored parity for Madrid in the 32nd minute to make it 1-1.
The hosts regained the lead in the 75th minute when Pilios found the net. Madrid responded just three minutes later, with Mbappe scoring the equaliser to bring the visitors back into the game.
Valverde then completed the comeback in stoppage time, scoring the decisive goal to seal a 3-2 victory for Real Madrid.
With the win, Real Madrid moved to second place in the standings with 12 points from four matches. AEK Athens, meanwhile, remain 19th with three points from the same number of games.
