The match threatened to be a one-sided affair when the league leaders raced into a three-goal lead through Jordi Alba, Cristian Tello and Messi after just 18 minutes.
However, Deportivo replied with a Luis Pizzi penalty and an Alex Bergantinos goal before Messi struck again to put Barca back in the driving seat.
Pizzi's second of the match then set the nerves jangling once more and the dismissal of Javier Mascherano gave the visitors further food for thought until Messi made it 5-3 with his third.
The excitement did not stop there though, and an own goal from Alba brought the visitors back within touching distance of their opponents with 11 minutes remaining.
However, despite their best attempts to grab a deserved equaliser, their luck ran out as Barca held on for the points.
The recent international break has left Madrid short of options at the back, with fullbacks Marcelo, Fabio Coentrao and Alvaro Arbeloa facing spells on the sidelines, but they attacked from the off although Higuain's 11th-minute opener was a touch fortunate.
Ronaldo netted from the spot midway through the second half to settle matters after Mesut Ozil tumbled in the area following a rather innocuous challenge from defender Gustavo Cabral.
The win meant Madrid moved up to fourth.
Aritz Aduriz's first-half double, either side of a Roberto Soldado penalty, looked like it would be enough for Bilbao despite Ander Herrera's dismissal on 67 minutes.
But after Tino Costa levelled with just two minutes remaining, substitute Nelson Valdez popped up to head in the winner with barely any time left on the clock.
Manucho had fired the visitors into a shock lead on just nine minutes but Isco levelled the scores eight minutes before half-time with an accurate low finish from Eliseu's cutback.
The game appeared to being going Malaga's way when Manucho was harshly sent off for a second yellow card nine minutes from time and then the hosts were awarded a penalty when Henrique Sereno felled Javier Saviola in the area, but Joaquin blazed his spot-kick over.
However, the former Spain international made amends two minutes later when he pounced after Dani Gimenez could only parry Martin Demichelis' header back into the danger area.
Substitutes Martin Cáceres and Paul Pogba both struck in the last 10 minutes to earn the Bianconeri all three points at the Juventus Stadium.
It was Napoli's first defeat of the season, their second to Juventus when considering the Italian Supercoppa between the two sides in August.
With Juventus assistant manager Angelo Alessio on the bench for the first time after his suspension for match-fixing was reduced, it was business as usual for the Turin-based club as they await the return of head coach Antonio Conte in December.
Hernanes, Antonio Candreva and Miroslav Klose put Lazio firmly in the driving seat at 3-0 up, but goals from Nigel de Jong on the hour mark and a Stephan El Shaarawy strike 10 minutes later set up a grandstand finish.
However, Lazio held on to all three points, taking them up to third in the table and leaving Milan just two points above the relegation zone in 13th after a fifth defeat in eight league matches.
Paris St Germain moved to the top of the Ligue 1 table - for 24 hours at least - after scraping past Reims at the Parc des Princes.
The big-spending Parisians were far from their best and had fortune on their side with Reims' Diego seeing a first-half penalty superbly saved by the hosts' Salvatore Sirigu.
PSG rode their luck and grabbed the winner when Maxwell crossed for Kevin Gameiro to nod in at the far post.
Carlo Ancelotti's side edged ahead of arch-rivals Marseille on goal difference at the summit although OM can re-establish their three-point advantage when they go to Troyes tomorrow.
Toulouse moved up to third after Emmanuel Riviere's brace inflicted more misery on struggling Evian in a 4-0 beating.
The hosts are suffering from 'second season syndrome' after a strong showing in the top flight last term following promotion.
And they were second best once again as Toulouse ran riot thanks to some clinical finishing, Riviere's strikes being sandwiched by efforts from Franck Tabanou and Daniel Braaten.
Lorient endured a night to forget as Valenciennes took advantage of two red cards with a late flurry of goals to win 6-1.
The visitors actually took an early lead through Benjamin Corgnet but were 2-1 down before Arnaud Le Lan's 18th-minute dismissal, Carlos Sanchez and Anthony Le Tallec doing the damage.
Gael Danic's penalty and a second Lorient red card - Innocent Emeghara failing to live up to his name - put the result beyond any serious doubt and two goals in the final 10 minutes from Vincent Aboubakar, plus another for Le Tallec, inflicted maximum punishment on Christian Gourcuff's side.
Reigning champions Montpellier's scarcely believable start to the season continued as a 2-1 defeat at Rennes left them with only eight points from nine games.
Jean Makoun's 12th-minute header and Mevlut Erding's goal early in the second half set Rennes on their way to victory.
Younes Belhanda pulled a goal back from the penalty spot but it was not enough to save Montpellier from their fifth defeat of the campaign.
Nice were left ruling a late missed penalty as their match against St Etienne finished 1-1 at the Stade Municipal du Ray.
Eric Bautheac gave Nice a 28th-minute lead, which was cancelled out by Brandao's goal 14 minutes from time.
Ten-man Nancy ended their abysmal run of form but were pegged back by Sebastien Roudet's second-half strike in their 1-1 draw with fellow strugglers Sochaux.
Jean Fernandez's side had lost their last six matches but made an ideal start with Sebastien Puygrenier opening the scoring with the first chance of the match in the 13th minute.
Yet Sochaux dominated thereafter and Roudet's leveller 10 minutes after the interval was richly deserved before Djamel Bakar was dismissed on the hour mark for a rash lunge on Ryad Boudebouz.
Celtic warmed up for a trip to the Nou Camp by thrashing St Mirren 5-0 in their Premier League clash in Paisley.
Goals from Gary Hooper and Efe Ambrose, then Victor Wanyama's double, gave an understrength Hoops side an unassailable interval lead against sorry-looking Saints.
Tony Watt scored with four minutes remaining to seal a commanding victory, which manager Neil Lennon would have wanted ahead of their Champions League Group G clash with Barcelona on Tuesday night.
St Johnstone lifted themselves up to second place with a fifth consecutive top-flight win for the first time since 1971.
Murray Davidson set the Perth side on their way against Kilmarnock with a scrappy opener in the 29th minute, and it stayed that way until a minute from time when Nigel Hasselbaink netted a second. James Fowler scored an injury time consolation for Killie.
A late goal from Colin McMenamin, his first of the season, was enough to earn Ross County their first home victory in the SPL, 3-2 over Hibernian.
In an entertaining match, Leigh Griffiths gave Hibs the lead in the sixth minute but Stuart Kettlewell levelled three minutes later.
Iain Vigurs then gave County the advantage in the 34th minute before Hibs equalised through James McPake on the stroke of half time.
The match looked to be heading for a draw in an equally entertaining second half but super sub McMenamin popped up with the winner seven minutes from time.
Niall McGinn was on target as Aberdeen extended their unbeaten run to 11 games with a 1-1 draw against Dundee United that left the hosts winless in six.
John Rankin's 22nd-minute goal was cancelled out eight minutes into the second half by McGinn, who netted in Northern Ireland's midweek draw in Portugal on the occasion of Cristiano Ronaldo's 100th cap.
Bayern Munich made it a record-breaking start to the Bundesliga season by recording their eighth successive win by routing Fortuna Düsseldorf 5-0.
Looking to beat their own record of seven straight wins from the season's outset, they emphasised their current superiority in German football with Mario Mandzukic and Luiz Gustavo giving them a two-goal advantage at half-time.
Thomas Muller added two more for the record German champions and Rafinha rounded off the comprehensive victory in the 87th minute of a one-sided game.
Defending champions Borussia Dortmund slipped further behind rampant Bayern after they were stunned 2-1 by Schalke in the Revier derby.
Ibrahim Afellay and Marco Hoger scored the goals for Huub Stevens' side, who emerged triumphant in the 141st derby encounter between the two sides, with Poland striker Robert Lewandowski's effort proving scant consolation.
Eintracht Frankfurt bounced back from their first defeat of the season to see off Hannover 3-1 and remain five points adrift of Bayern in second.
The hosts were defeated by Borussia Monchengladbach before the international break but looked firmly on course to return to winning ways after Karim Matmour and Sebastian Jung put them 2-0 ahead.
Although Mohammed Abdellaoue pulled a goal back for Hannover shortly before the break, Alexander Meier made the points safe for Eintracht with eight minutes to go.
Gonzalo Castro's 87th-minute strike rescued a 2-2 draw for Bayer Leverkusen at home to Mainz.
Stefan Kiessling put Leverkusen ahead just before half-time but Adam Szalai and Marcel Risse turned the game on its head before Castro struck late on to ensure the points were shared.
Daniel Caligiuri's strike five minutes before the interval and Julian Schuster's goal in the 84th-minute goal gave Freiburg their first win on the road at rock-bottom Wolfsburg, who suffered their fourth successive defeat.
In the late kick-off, Werder Bremen hammered Borussia Monchengladbach 4-0.
Nils Petersen broke the deadlock in the 37th minute before Marko Arnautovic doubled Bremen's lead on stroke of half-time, with Niclas Fullkrug scoring a minute after being introduced in the 75th minute and Zlatko Junuzovic completing the romp four minutes from time.