The game between RFS of Latvia and Hearts was an entertaining one.
Alan Forrest's strike in the final seconds of the game sealed the victory.
Craig Gordon was the hero of the game, especially for tipping one effort on to the woodwork, but they also passed up good chances to add to their tally.
As a result of Istanbul Basaksehir's win over Fiorentina, Hearts moved to second in Group A behind the Turkish club.
The win in Riga keeps some hope of progression for injury-hit Hearts, who were handed a sixth loss in seven games by Basaksehir last week.
At various stages of the first half they looked rattled, especially when centre-back Craig Halkett left the field with an injury.
RFS hit the woodwork after two minutes when Gordon tipped the ball onto the woodwork.
The Hearts keeper made two stops in a row to keep his team in front at the half.
In spells before the break, Hearts were as dangerous as they were in the second half.
After Elvis Stuglis blocked Andy Halliday's cross with his arm, and Josh Ginnelly missed an open goal on the stretch, Shankland stroked his penalty into the top corner to make it 2-0.
Nevertheless, Hearts did more than enough to earn a difficult victory, their first in European group stage football for 18 years, and made sure of it when Cammy Devlin broke free at the end to set up Forrest for the winning goal.
When he switched to a back four for this match, he made it clear that he would use Barrie McKay and Josh Ginnelly to cause problems with their dribbling.
It was the right approach against an inferior team that has recently shocked the world. McKay's touch and driving run helped in the lead up to the penalty, while Ginnelly was lively.
Halliday had many chances to score and was willing to drive forward from the middle of the field.
Gordon saved them on a couple of occasions, despite the fact that the commitment to pour more bodies forward came with risk.
The decision to play Halkett was a gamble which did not pay off.
A few more weeks out could do more damage to the team in the long run because of his absence.
The dream of qualification for the last-16 remains alive, despite the fact that Hearts appeared to swell in confidence as the match progressed.
Before the international break, Hearts are away to Motherwell in the Scottish league.