Home manager Michael Laudrup had come under scrutiny after a run of form which saw his side lost their last three La Liga games without scoring a goal.
But midfielder Emilio Nsue had insisted the squad was determined to win in order to save the manager's job.
The hosts started the match in 15th with just three points from four games courtesy of a 1-0 victory over Espanyol - their only goal so far this season.
They did not get off to the best of starts either, Carlos Vela hitting the post for Sociedad after 12 minutes before Imanol Agirretxe put the visitors ahead two minutes later.
Carlos Martinez sent in a right-wing cross which found Agirretxe who slotted home with a right-footed shot low into the centre of the goal.
However, the hosts responded, Jose Luis Marti firing a long-range effort over the bar before the hosts equalised five minutes after the visitors' opener, Victor crashing in right-footed from the centre of the box from Nsue's pass.
There were few clear-cut chances for either side as the half progressed and the sides went into the break level.
Seconds after half-time, though, Sociedad almost regained their lead.
Sergio Tejera fouled Xabi Prieto and from the resulting free-kick Vela drilled in a left-footed shot from the right which was parried by Dudu Aouate.
However, it was Mallorca who shortly after went on to take the lead for the first time in the game.
Ivan Ramis passed from the left of the penalty area to Castro who sent a 20-yard shot into the bottom right-hand corner of the goal.
As expected, Sociedad hit back, Agirretxe heading Antoine Griezmann's corner over from six yards.
Griezmann then shot over as the visitors probed for an opening before Agirretxe came agonisingly close with less than 10 minutes left when his right-footed shot from the centre of the box hit the bar following a ball from Asier Illarramendi.
Time was running out for Philippe Montanier's side as they looked for their second away win of the season.
Griezmann hit wide before his 20-yard attempt from the right was comfortably saved by Aouate as the game entered injury-time.
Mallorca attempted to take advantage of any gaps left by Sociedad pushing for the equaliser but Tejera shot high over the bar and Victor went wide.
And there were no further chances for the visitors as Mallorca celebrated moving up the table.