Luis Suarez's 88th-minute winner against Osasuna has left Atletico Madrid on the brink of clinching the LaLiga title for only the second time since 1996.
Diego Simeone's side were staring at a shock defeat after Ante Budimir headed the visitors in front with just 14 minutes remaining.
But substitute Renan Lodi netted for Atletico in the 82nd minute before Suarez's late decider.
Atletico, who were champions in 2014 under Simeone, head into the concluding round of fixtures next Sunday with a two-point advantage over Real Madrid.
Real host Villarreal on the final day, while Atletico travel to Real Valladolid.
Messi briefly dragged Barca to within two points of Atletico when he put his side ahead, but Santi's double created an insurmountable gap for Ronald Koeman's men.
The result means the Catalan club will finish outside the top two for the first time since 2008 as their Madrid rivals Real and Atletico are now out of reach.
Elsewhere in Spain, Eibar were relegated from LaLiga following a 4-1 defeat at Valencia. The result leaves them three points behind Huesca, who lost 1-0 away at Real Betis, with a worse head-to-head record.
Elche won 3-1 at Cadiz to provide themselves with a chance of staying up.
Carlos Bacca scored a hat-trick as Villarreal secured a 4-0 win against 10-man Sevilla, while Real Sociedad also scored four times in a 4-1 home win against Valladolid.
Takefusa Kubo struck in the 84th minute in a 2-1 triumph for Getafe against Levante, while Alaves ran out 4-2 victors against Granada.