Ronald Koeman's side had looked set to follow Real Madrid and Atletico Madrid in losing to lower-league opposition when Fran Garcia gave Segunda Division side Rayo the lead shortly after the hour-mark.
As is so often the case, though, Messi pulled Barca level soon after with a close-range finish.
That set the stage for the impressive De Jong to secure Barca's progression 10 minutes from time.
The first clear sight of goal did not come until the 20th minute, De Jong looping an effort from six yards onto Stole Dimitrievski's crossbar.
The visitors somehow failed to take the lead 10 minutes before the interval when Dimitrievski initially pawed away Trincao's strike before Riqui Puig's follow-up was diverted onto the crossbar by Ivan Martos.
Antoine Griezmann and De Jong had further chances, but Barca were ultimately unable to make their superiority count at the break.
Messi clipped the top of the crossbar with a free-kick three minutes after the restart before the Argentina international blazed over after being played clean through soon after.
Barca were made to rue those misses in the 63rd minute when Fran Garcia turned home from almost on the line after Neto had parried Alvaro Garcia's cross into his path.
Messi restored parity six minutes later, however, sliding in from six yards after being teed up by Griezmann.
De Jong ensured there would be no need for extra time to settle the result, stroking home from a similar position to Messi from Jordi Alba's cross.