The Spanish side lost away in Germany which left their hopes of qualifying for the next round looking remote but now they are on five points, one behind Leverkusen and three behind leaders Chelsea who surprisingly drew away to Genk.
In a dramatic start to the game Jonas Goncalves put Valencia ahead in just over ten seconds which was fractionally slower than the fastest ever in the competition by Roy Makaay for Bayern Munich against Real Madrid in 2007 which was measured at 10.3secs.
Leverkusen keeper Bernd Leno cleared the ball straight to Jonas and he slipped the ball home from 18 yards.
Stefan Kiessling headed Leverkusen level but Roberto Soldado restored Valencia’s advantage after 65 minutes and French centreback Adil Rami added a third 15 minutes from the end.
"These are three points which gives us cause for optimism," said Valencia coach Unai Emery.
"We have a difficult game next (against Genk) but we know that despite being behind at the moment we have serious chances of qualifying. The final match is against Chelsea as well and they are likely to have qualified by then."
Leverkusen coach Robin Dutt was also positive about his team's hopes of qualifying.
"We cannot leave the Mestalla happy with the result but yes with the way we played. It was a good game between two strong sides and it is down to us how we now do in the group.
"It will be a difficult game against Chelsea but also Genk who have drawn with Chelsea and Valencia," he said.
Valencia had the perfect start when a calamitous kick from keeper Leno went straight to Jonas on the edge of the area and he clinically slotted the ball into the bottom corner.
The visitors were shaken and it took them a while to settle down as Valencia had control in the centre of the pitch and stretched the Leverkusen backline especially through the dangerous Pablo Hernandez.
Leverkusen possessed a physical threat in attack which Valencia were not comfortable with and an excellent save was needed from Diego Alves to deny an Omer Toprak header from a corner.
It was an open game but Valencia were dealt a blow with the loss of creative midfielder Ever Banega with an ankle injury midway through the first half.
Sidney Sam hit a drive from the edge of the area which was well parried by Alves but he could do nothing on 31 minutes when Leverkusen’s aerial threat brought the equaliser.
Ballack picked out Kiessling with an excellent cross who nodded the ball into the corner.
It was a busy first half for Alves who also had to tip over a powerful strike from Andre Schurrle, while Valencia continued to attack down the wings.
The game maintained a lively pace after the break as Valencia needed to push forward looking for the win but they struggled to create clear cut chances and Leverkusen were carrying a greater threat on the break.
Valencia coach Unai Emery threw on the tricky Pablo Piatti as the hosts searched for a way through but as when the two teams met in Germany it appeared that the game was going away from them after a bright start.
It was when Leverkusen were looking at their strongest that Valencia retook the lead. Jeremy Mathieu raced down the left wing and crossed low for Soldado whose shot squeezed under the keeper.
The goal relaxed Valencia and Costa became more and more influential in the middle of the pitch after taking his time to get into the match as a substitute.
It was his corner which was headed home by Rami that sealed the win for Valencia.
What the stars mean:
★ Poor ★ ★ Promising ★★★ Good ★★★★ Very good ★★★★★ Exceptional