Ljajic ran the show for the visitors and against a team coached by former Fiorentina boss Delio Rossi, who lost that job following a violent altercation with the Serbian last May.
He scored the second just before the break, adding to Juan Cuadrado's opener, before setting up Alberto Aquilani for the third.
The victory boosted Fiorentina's hopes of qualifying for the Champions League.
Fiorentina's first chance came after 12 minutes when Cuadrado got down the right and crossed for David Pizarro, who shot from the edge of the box, but Sergio Romero got down well to save.
Three minutes later Sampdoria's Maxi Lopez picked out Andrea Poli, but his shot from the edge of the box went high over the bar.
Just after the half hour Cuadrado tried a lob but Romero tipped it over the bar.
Fiorentina finally took the lead nine minutes before half-time when Cuadrado shot from long distance and found the bottom corner.
Four minutes before half-time Ljajic doubled their advantage with a well-taken goal.
Ljajic pounced on a loose ball in the Sampdoria area and shot across Romero to score at the far post.
Two minutes into the second half Aquilani tried his luck from the edge of the area but shot over the bar.
At the other end Gaetano Berardi's shot from outside the area was well off target.
And with 17 minutes remaining Fiorentina scored a third when Ljajic got down the right and crossed low for Aquilani, who scored from close range.
Sampdoria's misery was completed 10 minutes from time when Gastaldello was shown a red card for his foul on Ljajic, which denied the Serbian the chance of another goal.