Yet they looked to be heading for a scrappy goalless draw after wasting several chances before man-of-the-match Gakpo beat goalkeeper Edouard Mendy to nod in Frenkie de Jong's cross with the back of his head.
Klaassen then pounced on a weak Mendy save to score on the rebound nine minutes into stoppage time.
The Dutch join Ecuador, 2-0 winners over hosts Qatar on Sunday, on three points, with the top two meeting on Friday.
"At times we may have been too rushed and tried to force things," said Netherlands captain Virgil van Dijk. "But in the end Cody did it very well.
"In midfield, however, if you lose possession it is open and they (Senegal) can be dangerous with their speed. That has to be better because Ecuador also have the speed that can hurt you on the counter.
"We will have to work on that, but it can only get better from here. That's how it feels," said the defender.
The 23-year-old Gakpo, who has now scored three times in his last four internationals, had the Netherlands' first opportunity after four minutes but tried to square the ball to Steven Bergwijn instead of going for goal.
That was followed by a Daley Blind header at the far post that flew wide before Steven Berghuis sent Bergwijn through and he laid the ball off for the unmarked De Jong in the box.
The midfielder took far too long to release the ball, however, and his effort was blocked.
The African champions were badly missing injured talisman Sadio Mane and did not manage a shot on target until the 65th minute when Boulaye Dia tried to sneak one past goalkeeper Andries Noppert, making his Dutch debut, from a tight angle.
Senegal had a bit more possession in the second half but despite the relentless drumming from their small fan group in the stands they could not find the back of the net.
To make matters worse, Cheikhou Kouyate had to be taken off injured before Gakpo sneaked in to snatch the opening goal.
Klaassen made sure of the points with a tap-in in stoppage time after Mendy palmed a Memphis Depay shot into his path.