Italy came close to losing a game they had already won with careless turnovers but Spain guard Miguel Servera missed a three-pointer at the final buzzer, allowing the Azzurri to celebrate a 78-76 victory.
The result means that Italy improve to 2-2 in Group F of the U20 European Championship, level with Spain in the standings, and maintain their hopes of qualfying to the Quarter-Finals intact.
With just over a minute to go Italy led 75-66, but turned the ball over four times under immense pressure from Spain, who got themselves into a position to win the game on the last possession.
Awudu Abass led Italy with a monstrous double-double of 24 points and 12 rebounds, while Andrea Traini chipped in with 18 points.
Daniel Diez scored 17 points and grabbed seven boards for Spain but the player's effort wasn't enough, as the Spaniards were outscored 34-24 in the paint.
Italy will play Latvia on the last day of the Second Round, while Spain will attempt to upset the hosts, Slovenia.