After a goalless first half, Ramos opened the scores from the penalty spot when Vinicius Junior was fouled in the Sociedad box five minutes after half time. The 34-year-old in the process took his tally in the Spanish top flight to 68, one clear of former Barcelona and Holland defender Ronald Koeman.
Ramos scored his first two La Liga goals for former club Sevilla before joining Real Madrid in 2005 and scoring the next 66 for Los Blancos.
Former Real Madrid defenders Fernando Hierro and Roberto Carlos are next on the list with 51 and 46 La Liga goals respectively.
Karim Benzema doubled Real Madrid’s advantage 20 minutes later but Mikel Merino halved the deficit for the hosts seven minutes from time, setting up a nervy finish for Zinedine Zidane’s men.
Ramos has won four La Liga titles, four UEFA Champions League trophies and two Copa del Reys among numerous honours in his Real Madrid career. He is also a two-time European Championship winner with Spain and hoisted the FIFA World Cup with La Furia Roja in 2010.
Real Madrid have now overtaken Barcelona at the top of the La Liga table with a better head-to-head difference despite both sides accumulating 65 points from 30 games. There are just eight games remaining.