But Marius Stankevicius levelled 11 minutes after the break and it needed the intervention of substitute Mata, who brought about an own goal from Tadas Kijanskas after 70 minutes and finished himself six minutes from time, to decide things in Spain's favour.
The result extended Spain's 100 per cent start to their qualifying fixtures, and ensured they kept their lead at the top of Group I at six points over the Czech Republic, who beat Liechtenstein earlier.
Such was the difficult nature of the pitch at that there was some uncertainty ahead of kick-off as to whether the match would go ahead. But go ahead it did, and it was Spain striker David Villa who was quickly to the fore.
Villa stole the headlines on Friday when he notched his 45th and 46th international goals to become Spain's all-time leading scorer. And he was quickly hunting for number 47, but his shot from 20 yards was held by Lithuania goalkeeper Zydrunas Karcemarskas.
But he did make a decisive contribution in the 20th minute as he and Barcelona team-mate Xavi switched their usual roles. For a change it was the striker who played in the midfielder and Xavi struck the ball home from 25 yards.
Javi Martinez had the opportunity to double the lead in the 27th minute but his shot was too close to Karcemarskas, who held on.
The hosts had chances of their own before the break, with Darvydas Sernas failing to find the target from out wide just before the half-hour mark and Mindaugas Panka bringing a save out of Iker Casillas with an ambitious strike from 30 yards as half-time loomed.
Villa was withdrawn eight minutes after the restart, replaced by his former Valencia team-mate David Silva. And the Manchester City man had been on the pitch barely three minutes when his team were pegged back.
Deividas Semberas on the left found Stankevicius, whose 25-yard effort was good enough to beat Casillas. That spurred Spain into action and when Tomas Danilevicius fouled Fernando Llorente 25 yards from goal, Xabi Alonso drilled a free-kick towards goal, which Karcemarskas got enough on to turn behind.
Spain coach Vicente Del Bosque brought Mata on in the 66th minute and it proved to be an inspired change as he was involved in Spain's second four minutes later. The Valencia winger advanced down the left and played the ball into the centre where Kijanskas, under pressure from Llorente, headed into his own net.
Alonso's free-kick was blocked by Semberas four minutes later after Andrius Skerla had fouled Llorente. But a third goal did come, with Xavi this time assuming the more familiar role of creator as he played in Mata to finish from 12 yards to cap his match-changing cameo.