The visitors went into half-time 2-1 ahead as Emilio Nsue and Alejandro Alfaro scored from free headers either side of Gonzalo Higuain's reply for Madrid, and Mallorca could easily have gone 3-1 up when Alan Hutton headed just wide.
"Set-pieces have caused us problems since the start of the season," Karanka told a press conference.
"It is due to a lack of concentration and communication and obviously it is something we have to keep improving on for the final part of the season."
Luckily for Los Blancos the introduction of Mesut Özil and Karim Benzema at half-time turned the game around as three goals in six minutes from Cristiano Ronaldo, Luka Modric and Higuain gave them a comfortable lead before Benzema rounded off the scoring in stoppage time.
"In the first-half we were making a lot of errors, not only in the goals but in giving the ball away and committing stupid fouls," said Karanka.
"With the changes Kaka and Modric were able to gain possession and I think the squad is built for this."
"You can put out the team you think is best but like against Deportivo a couple of weeks ago or today, the important and good thing is we can change
the dynamic of games with those that come on."
Although still in the bottom three, Mallorca had won their two previous games and went in front after just six minutes as Giovani Dos Santos burst
down the left and his cross was brilliantly headed into the bottom corner by Nsue.
The lead only lasted eight minutes though as Modric released Pepe clear on goal and he squared for Higuain to roll home the equaliser.
However, Mallorca were still posing a threat and went in front again when Giovani produced another fine cross from a corner that was flicked on by Pedro
Bigas and headed in at the back post by Alfaro.
And things could have been even worse for Madrid at the break as Hutton then glanced a header just wide as the hosts continued to struggle from
Jose Mourinho reacted by introducing Özil and Benzema at the break, but it was again Mallorca who had the first opportunity of the second-half as Bigas
spooned an overhead kick over the bar when completely unmarked just six yards out.
And that miss was to prove crucial as a rapid three-goal salvo decisively swung the game in the hosts' favour.
Firstly, Ronaldo leapt highest to nod in an Özil corner from the right before Modric volleyed in a wonderful strike from fully 30 yards three minutes later.
Özil's impact was felt once more moments later as he showed great composure to lay the ball across the face of goal for Higuain to fire in his second of
And Madrid finished with a flourish as Higuain crossed for Benzema to round off the scoring as they cut the gap on Barcelona at the top of the table to 10 points ahead of the Catalans' clash with Rayo Vallecano on Sunday.
Meanwhile in the race for the final Champions League spots, Real Sociedad strengthened their position in fourth with a 4-1 hammering of Valladolid thanks to goals from Imanol Agirretxe, Xabi Prieto and two from Antoine Griezmann.
Valencia moved up into fifth, just two points behind the Basques, as they beat Real Betis 3-0.
Betis were dealt an early blow as Antonio Amaya was sent-off and Roberto Soldado converted the resultant penalty before Paulao's own goal and a strike from Jonas late on sealed the win.
And Getafe moved up to eighth as they stretched their unbeaten run to five-games with a 1-0 win over Athletic Bilbao.