The Spanish saw more of the ball in the opening stages but it was their opponents who almost drew first blood in the 12th minute as Anice Badri's ball into the box caught their defence off guard, allowing Ferjani Sassi to get a shot away, which flew into the arms of David De Gea.
Tunisia missed a sitter just after the half-hour mark as Badri's dangerous cross found Sliti unmarked at the far post, but the Lille midfielder put too much on his strike and skewed it off target.
Spain found their rhythm in the second period but Tunisia restricted them to long-range efforts for much of it, one of which came from Jordi Alba shortly after the restart as he blazed the ball over the crossbar.
Manchester City's David Silva was next to try his luck for the Spaniards, collecting a pass from Ramos before unleashing a curling effort that dipped just wide of the mark with one hour played.
Tunisia gave as good as they got throughout the match but Spain's finishing let them down for much of the duration, and Real Madrid striker Marco Asensio joined a long list of their players who failed to find the target in the 75th minute when he prodded a cut-back wide from inside the box.
Spain's winner came in the 84th minute after Diego Costa danced into the penalty area before squaring a pass to Aspas, who made the net ripple with a screamer from 12 yards out.
Aspas's strike proved the last meaningful chance for either side as Spain saw out the match to end their World Cup preparations on a positive note.
Lopetegui's men face Portugal, Iran and Morocco in the group stage at the finals, while Tunisia are up against Panama and Belgium as well as England.
SPAIN (4-5-1): De Gea; Alba (Aspas 76'), Odriozola, Pique, Ramos; Iniesta, Alcantara (Koke 45'), Busquets, Silva (Asensio 60), Isco (Vazquez 45'); Moreno (Costa 60')
TUNISIA (4-3-3): Mathlouthi; Meriah, Maaloul (Haddadi 58'), Bronn, S. Ben Youssef (Srarfi 91'); Sassi, Skhiri, Khaoui (Ben Amor 62'); Badri (Benalouane 78'), F. Ben Youssef, Sliti (Khalifa 69')