The pace of Mallorca's Giovani dos Santos was a constant threat but Portugal defender Costa rose at the back post to power a header under the bar from a corner in the 60th minute.
Mallorca, second bottom of La Liga, have one win from their last 19 league outings.
Later on Sunday, second-placed Atletico Madrid, with 50 points, visit Real Valladolid looking to close the 15-point gap on leaders Barcelona, who won 2-1 at Granada on Saturday with a Lionel Messi double.
In the midday kickoff, Levante stalled Real Sociedad's push for European football next season by holding them to a 1-1 draw with 10 men, both goals coming from first-half penalties.
Carlos Vela gave the Basques the lead and Michel levelled, but Levante hung on despite a second yellow card for defender Nikos Karabelas early in the second period.
Real Sociedad are sixth with 37 points.