Meli crashed over to inflict the same misery on the Tigers that St Helens had suffered with their late defeat at Wigan on Good Friday.
But it was still left for Foster to boot the decisive touchline conversion after the final hooter had sounded.
Tigers coach Terry Matterson said: “Our boys are devastated, and they’ve got a right to be.
“We were outstanding today and we’ve had it taken away from us. We were the best side, and we didn’t get one call all game.”
He added: “We didn’t run out of gas – he (referee Phil Bentham) kept putting petrol in their tank. That was the difference.”
Castleford’s afternoon was made even worse by the news that Craig Huby appeared to have suffered a serious knee injury while attempting to tackle Sia Soliola in the 68th minute.
However, Saints’ own selection problems have been intensified after Jonny Lomax (ankle), Tommy Makinson (dead leg) and Scott Moore (ankle) all suffered problems that could keep them out of next week’s clash with Hull.
Saints boss Royce Simmons must now plan with even more of his junior players in mind, but he admitted he was delighted to claim two unlikely-looking points after watching Foster’s kick sail over.
He said: “My nerves aren’t real good. You’re never 100 per cent sure that you’ll kick the goal.
“Jamie missed one beforehand, but his average probably says he’s going to knock it over for you. It shows how important goal-kicking is.”
He added: “We didn’t play that tremendously, and we were very impatient, but there was a real energy rise in the last 10 minutes.”
Makinson’s early departure had paved the way for substitute Tom Armstrong to cross for two tries before the break.
Tigers were undoubtedly disrupted by Huby’s injury, but Saints showed the kind of resilience they were once famed for by first working Ade Gardner over before Meli’s try and Foster’s kick brought the house down.