The Cubs twice came from two runs down, including in the ninth when Darwin Barney hit a two-run home run and forced extra innings.
Castillo opened the Chicago 11th with a single and moved up on a sacrifice and took third on a fly out. DeJesus then, with the count 0-2, singled solidly to right and ended the game.
Alberto Cabrera (1-1) pitched the 11th for the Cubs and got the win while Joe Kelly (5-7), who came in for the Cardinals in the 10th, took the loss.
Fernando Sales was brought in by St. Louis to protect a 4-2 lead in the ninth and got the first two outs. But DeJesus, who had four hits, singled and Barney followed with his seventh home run of the season.
The Cubs tied the score 2-2 after DeJesus led off the third inning with a triple and scored on Barney's single. Barney reached home all the way from first on a double by Alfonso Soriano.
Pete Kozma led off the next inning with a triple of his own and the Cardinals called for a squeeze play but the pitch was high and Castillo, the Cubs' catcher, was unable to handle it. Kozma was able to cross the plate standing up and was credited with a steal of home.
Aaron Carter is still in love with Hilary Duff
Ray Liotta sues skin care company over use of likeness