Joe Thompson netted the opener but Gytis Paulauskas scored either side of half-time to put the Vilnius hosts ahead.
Eoin Toal headed home an equaliser for Declan Devine’s side midway through the second half.
Donatas Kazlauskas scored a superb winner 40 seconds in extra-time to send the home side through.
Thompson opened the scoring on 18 minutes when the wide man collected Ibrahim Meite’s knock-down and guided a ball past the Tadas Simitas from just inside the area.
Derry controlled possession but Riteriai found themselves level when a cross from Kazlauskas was headed home by the impressive Paulauskas on 38 minutes.
The striker scored again four minutes into the second half with another powerful header, this time from Mindaugas Grigaravicius’s cross, which Cherrie could not keep out despite getting a hand to it.
Devine got the response he was looking for when defender Toal netted his first goal of the season after rising highest to nod home from Adam Hamill’s cross on 63 minutes.
Paulauskas almost headed into his own net from Stephen Mallon’s teasing cross and James Akintunde missed two chances in injury-time as Derry went into extra-time for the first time in their European history.
Kazlauskas got the hosts off to the perfect start 40 seconds after the restart with a superb finish, cutting inside the area before bending an effort beyond the helpless Cherrie and into the top corner.
Ricardas Sveikauskas headed onto the top of the bar for the hosts, however there was concern for Derry midfielder Conor Clifford, who was carried off in a stretcher after colliding with team-mate Colm Horgan at the start of the second period.
Toal headed over the top as the game headed into injury-time however the home side held on to book their place in the second round.