Messi, who returned to Barca last week after completing the last stage of his recovery from a thigh operation in his native Argentina, replaced Andres Iniesta in the 64th minute, just after midfielder Cesc Fabregas had scored his second of the night from the penalty spot.
Messi almost set up Pedro minutes after his arrival on the pitch, but he soon found the back of the net himself when Sergio Busquets floated a ball to Martin Montoya, with the striker pouncing on the rebound from goalkeeper Jordi Codina.
The returning star then added his second three minutes later in the third minute of stoppage time after he raced onto the end of Alex Song's through ball to rifle it past the Getafe gloveman.
Fabregas, who had opened the scoring with an eighth-minute header before putting away the second from the spot in the 63rd minute after Valera brought down Pedro, had already been awarded the man of the match award before Messi's late double.
In the other games, Ruben Castro's 42nd-minute score was enough for Real Betis to beat Athletic Bilbao 1-0 while Dani Pacheco's 71st-minute score for Alcorcon saw the Segunda Division side account for Primera Division opponents Espanyol.
Racing Santander were held 1-1 at home by Almeria after Corona's first-half score was cancelled out by David Concha in the 65th minute, with Sundy Zongo Jonathan seeing red for the visitors eight minutes from time.