Argentine star Messi was with Barcelona, while Spanish defender Ramos played for Real Madrid since 2005 until they both transferred to PSG this summer.
The match started without much thrill, but Real Madrid's Austrian defender David Alaba opened the score in the 32nd minute at Camp Nou.
Both sides played an evenly matched game, and no goals were scored until the 90th minute.
Lucas Vasquez scored a late second goal in the 94th minute, and made it 2-0 for Los Merengues.
Just before the end, Sergio Aguero, who entered the game late, scored the only goal for Barcelona in the 97th minute and Real Madrid won 2-1 in the La Liga week 10 game.
With this victory, Los Merengues have defeated Barca four times in a row in official matches, an achievement which they haven't been able to pull off since 1965.
Real Madrid currently sit on top of the La Liga table with 20 points, while Barcelona are placed 8th with 15 points.