Getafe had seen their top-four bid hit by a four-game winless run since the league restarted following the coronavirus pandemic, but they moved back to within two points of fourth-placed Sevilla.
Sociedad, who were in the Champions League places before the COVID-19 lockdown, have picked up just one point from a possible 15 since and are now seven points adrift in seventh.
Sevilla's 1-1 draw with Real Valladolid on Friday had given Getafe a chance of narrowing the gap, and they took a 20th-minute lead through Mata's penalty.
Former Manchester United winger Adnan Januzaj levelled for visitors Sociedad 10 minutes after the break with his third league goal of the season.
But Mata had the final word with seven minutes remaining as he latched onto Jorge Molina's quick throw-in and poked a low finish into the net from the tightest of angles to send Getafe back into fifth.
Sixth-placed Villarreal remain in the Champions League hunt though, just one point further back.