Jon Dahl Tomasson's side beat Hungary 2-0 away from home on Friday and were aiming to take a third win on the bounce into their 2026 FIFA World Cup qualifying campaign which begins in September.
The Blagult were on their way by the 14th minute, when a cross to the back post was nodded down by Jordan Larsson into the path of Ken Sema, who steered in the opening goal.
Late in the first half, Sema made it a brace for himself when his venture forward was picked out by Alexander Bernhardsson, before the Pafos man made his way into the box and fired through the legs of goalkeeper Anthony Mandrea.
Shortly after the break, Sweden were awarded a penalty after Ramy Bensebaini fouled Bernhardsson inside the area.
There was only going to be one taker - up stepped Sema, who dispatched the spot kick to take his international goal tally from two to five in the course of 50 minutes.
Six minutes later, Anton Saletros got in on the act to make it 4-0 with a beautiful curling free-kick with his left foot from 25 yards out, his first goal for his country.
But from then on, it was all Algeria, who pulled their first goal back through Ismael Bennacer, who let fly with a 25-yard rocket, giving Viktor Johansson no chance in the Swedish goal.
19 minutes from time, the Desert Foxes made it 4-2 - Nabil Bentaleb worked some magic down the left side to get to the byline and cross for Yassine Benzia to bundle over the line.
With five minutes to play, Isak Hien fouled Amine Gouiri inside the area, and the resulting penalty was put away by Bentaleb to bring Algeria back within one.
But despite the nail-biting finish, Sweden held on for a memorable 4-3 victory.