Ronaldo put Madrid ahead after 23 minutes but Messi responded just after the half hour mark with Barca having shown little going forward.
The 98,000 capacity crowd of vociferous Catalans glimpsed the possibility of going 11 points clear after Messi struck a free-kick to put them ahead after the break but Ronaldo responded five minutes later.
In the dying stages, Barca had the chance to win it with Martin Montoya hitting the woodwork.
On a tense night at Camp Nou, fans created a mosaic of the Catalan flag, "The Senyera", in a clear demonstration of the nationalist fervour in the region where many want independence from Spain.
In a surprise move, Barca lined up with Adriano Correia in the centre of defence alongside Javier Mascherano with Carles Puyol and Gerard Pique both injured.
Real coach Jose Mourinho put his confidence in the side which won the league last season with Mesut Ozil returning to the starting line-up despite a poor start to the campaign where Luka Modric appeared to have moved above him in the pecking order.
In a cautious opening, Barca had possession but were generally too deep and the Madrid players were happy to sit on the halfway line, looking to pounce when their moves broke down.
Despite their impressive winning streak, which had yielded six victories in the opening six La Liga matches, Barca have lacked their usual silky passing and their hesitation was made worse by a lack of confidence in their defence.
Angel Di Maria had an early shot wide and Adriano was forced into a last ditch clearance but the first clear opportunity fell to Karim Benzema after 12 minutes.
However, volleying the ball on the full from a Ronaldo cross, he blazed wide.
The general air of nationalism was again demonstrated after 17 minutes and 14 seconds when fans raised their Senyera flags and chanted for freedom for Catalonia.
The moment was chosen as a reference to the fall of Barcelona in 1714 during the War of Spanish Succession when Catalonia came under centralised rule from Madrid.
Sergio Ramos had the chance to put Madrid in the driving seat after 20 minutes but allowed a clear header from a corner he was unable to hit the target.
Madrid looked the more incisive side going forward and they got their reward when Ronaldo beat keeper Victor Valdes at his near post with a low left-foot drive after being played in by Benzema.
The Frenchman then failed to double the advantage, leaning back with his shot from 12 yards, and the ball came back off the post while Di Maria hit the follow-up wide.
It got worse for Barca with Dani Alves limping off to be replaced by youth product Montoya.
But forced out of their shells, the game opened up and they equalised with their first opening.
Pepe jumped and failed to connect with the ball which dropped at the feet of Messi in front of goal and he slotted home.
The match lost its cageyness, but after the break neither side was able to take control with imprecise passing and niggly fouls creating few clear cut chances.
It was at this moment that Barcelona received a moment of inspiration from Messi with a 25-yard free-kick into the top corner after he himself had been fouled.
The goal was Messi's 17th in Clasico matches.
Ronaldo though was not to be outdone and, latching onto an Ozil pass in the area he finished clinically.
Barca finished the stronger with Montoya seeing a curling 25 yard shot crash against the upright.
Later Sunday, Atletico Madrid moved level with Barca on 19 points with a 2-1 win over Malaga for whom Brazilian defender Weligton put through his own goal in the last minute.
Colombian striker Falcao had put Atletico ahead after six minutes, scoring his eighth goal of the season, the same number as Messi and Ronaldo.
'Look' how the Sheena Bora case has taken a toll on Indrani Mukerjea
Photos: Katrina Kaif, Parineeti Chopra, Shilpa Shetty's movie outing in Juhu
Birthday special: 14 Bollywood actors who made it big on TV
Photos: Vaani Kapoor, Poonam Pandey, Sana Khan at fashion event
Photos: Rishi Kapoor, wife Neetu, daughter Riddhima at book launch