Edgar Gonzalez and Largie Ramazani gave the winless visitors a startling 2-0 lead at the Bernabeu.
Ten minutes later, Vinicius Jr. equalised, following a penalty kick by England midfielder Bellingham in the 57th minute.
Bellingham nodded over for Dani Carvajal to knock in the winning goal in the ninth minute of additional time.
Real Madrid moved two points clear of Girona at the top of La Liga with their thrilling late triumph.
However, if Girona defeats Sevilla at home later this evening, they may make a comeback to the top.
Real was predicted to easily defeat an Almeria team that had only managed one point on the road during their dreadful 2023–24 campaign.
But on the back of a goalless draw at home to Girona last time out, the Andalusian outfit stunned the hosts with a goal after 38 seconds.
Neat build-up play after they pinched possession allowed Lucas Robertone to slip in the unmarked Ramazani and his low effort wrong-footed Kepa Arrizabalaga.
Gonzalez’s sweetly-struck half-volley in the 43rd minute then flew over a flat-footed Kepa to increase Almeria’s advantage.
But Real were awarded a debatable penalty after the Video Assistant Referee (VAR) decided the ball had brushed the arm of Kaiky, with Antonio Rudiger deemed not to have committed a foul in the build-up.
Real Madrid’s Jude Bellingham stepped up to net his first La Liga spot-kick as he confidently sent Almeria goalkeeper Luis Maximiano the wrong way.
Almeria thought they had a third when Sergio Arribas slotted the ball past Kepa from Ramazani’s cross but the VAR overruled it.
Vinicius Jr then levelled with another controversial goal, which was initially ruled out for handball after the Brazilian appeared to guide it in with his arm.
However, the referee reviewed it on the pitchside monitor and overturned his original decision.
Almeria boss Gaizka Garitano was sent off for a second booking for dissent as Real snatched a winner in the ninth of 11 minutes of injury time.
ALSO READ: Dynamos Unveils 2024 Squad
A deep cross from a Real counter-attack picked out Bellingham who directed his header to the opposite side of the six-yard box where Carvajal applied a close-range finish.
For feedback and comments, please contact ZiMetro News on WhatsApp: +27 82 836 5828.