Getafe had another good opportunity to break the deadlock at La Rosaleda in the 37th minute when Pedro Leon found Castro inside the hosts' penalty area with a cross, but the latter's header went straight into the arms of Caballero.
Malaga punished their visitors for not taking their chances three minutes later when Roque Santa Cruz headed home Sergio Sanchez's cross against the run of play.
Getafe refused to give up and halved the deficit in the 70th minute through Juan Valera, who smashed home after collecting Alberto Lopo's long free kick. That made for an exciting final 20 minutes, but Malaga held on for a home win.
The result means that Malaga are now fifth in the league table, while Getafe are ninth.