The result has moved the Reds back to the top of the Champions League table on 15 points, having won all five of their games in the competition this term, while Real Madrid have dropped to 24th, now on six points from five matches, with Los Blancos losing three times in this season's Champions League.
Liverpool started on the front foot, with Darwin Nunez drawing a smart save from Real Madrid goalkeeper Thibaut Courtois in the fourth minute, before Raul Asencio just managed to clear off the line with Luis Diaz in close proximity.
Courtois was also required to keep out an attempt from Diaz in the first period, with the hosts very much the dominant outfit in the opening 45 minutes of action, but the two teams headed down the tunnel at 0-0.
The breakthrough arrived early in the second period, with Mac Allister brilliantly picking out the bottom corner after combining with Conor Bradley, and it was no more than the hosts deserved considering their dominance.
Real Madrid were awarded a penalty just before the hour when Lucas Vazquez was fouled inside the box by Liverpool defender Andrew Robertson, but Kylian Mbappe's spot kick was kept out by Caoimhin Kelleher.
Liverpool had a penalty of their own shortly after, with Mohamed Salah brought to the ground by Ferland Mendy inside the box, but the Egypt international could only strike the outside of the post with his spot kick.
The Reds did have their second in the 77th minute, though, with Gakpo heading a delivery from Robertson into the back of the net to make it a long way back for Real Madrid in the latter stages of the contest.
Carlo Ancelotti's side are currently only just clinging onto a playoff spot, but the night belonged to Liverpool, who have put down a huge marker in the competition by comfortably overcoming the holders.
LIVERPOOL VS. REAL MADRID HIGHLIGHTS
Alexis Mac Allister goal vs. Real Madrid (52nd min, Liverpool 1-0 Real Madrid)
Breakthrough! Liverpool take the lead in the 52nd minute of the contest, as Mac Allister picks out the bottom corner with a clever finish after combining with Bradley; the Reds deservedly lead at Anfield after an excellent start to the second period.
Kylian Mbappe missed penalty vs. Liverpool (61st minute)
Real Madrid have the chance to level the scores from the penalty spot after Robertson fouls Vazquez inside the box, but Mbappe sees his spot kick kept out by an excellent Kelleher save. Huge moment in this Champions League clash!
Mohamed Salah missed penalty vs. Real Madrid (70th minute)
Now Liverpool miss one! The Reds are awarded a penalty when Salah goes down inside the box under a challenge from Mendy, but the Egypt international strikes the outside of the post with his spot kick - incredible scenes here.
Cody Gakpo goal vs. Real Madrid (77th min, Liverpool 2-0 Real Madrid)
Liverpool double their advantage in the 77th minute of the contest, as Gakpo heads an excellent delivery from Robertson into the back of the net; it is a long way back for Real Madrid at this stage of proceedings.
MAN OF THE MATCH - CONOR BRADLEY
Bradley's night ended in disappointment, with the Liverpool defender going off the field with a suspected hamstring issue late on, but he was simply sensational for the Reds during the standout Champions League win.
Mbappe found it incredibly difficult against Bradley, who provided the assist for Mac Allister to make the breakthrough, while he had two shots, made four tackles and completed 41 of his 48 passes during an outstanding performance.
LIVERPOOL VS. REAL MADRID MATCH STATS
Possession: Liverpool 63%-37% Real Madrid
Shots: Liverpool 16-10 Real Madrid
Shots on target: Liverpool 7-4 Real Madrid
Corners: Liverpool 8-5 Real Madrid
Fouls: Liverpool 10-10 Real Madrid
BEST STATS
WHAT NEXT?
Both sides will now switch their attention back to domestic matters; Liverpool have the small matter of a clash with English champions Manchester City on Sunday afternoon, and a win would see Arne Slot's side move 11 points ahead of the Citizens in the Premier League table on the same number of matches (13).
Real Madrid, meanwhile, will be aiming to make it three successive wins in Spain's top flight when they host Getafe on Sunday afternoon; Los Blancos are currently second in the La Liga table, four points behind the leaders Barcelona with a game in hand.