Second half goals from Aaron Haswell and Nick Hutton put Town in a good position from where, despite a late Railway rally, they were able to claim the silverware.
The contest started at a high tempo, with both sides desperate to claim a first bit of silverware of the season.
The ball ended up in the net three times in the first half, twice for Town and once for Railway, but each attempt was ruled out as the sides entered the break level.
Haswell, who was one of the unfortunate trio to have a strike ruled out, broke the deadlock seven minutes into the second half with a low strike through the 'keeper's legs.
Railway nearly levelled five minutes later, but an impressive Joe Wilton double save kept Town ahead.
The miss would prove costly though as, with 18 minutes to play, Hutton struck a sweet volley from the edge of the area that beat the stranded 'keeper.
Railway responded with a goal five minutes later as Jake Boyd headed home a left wing cross from close range, setting up an exciting finish.
The visitors looked for a late equaliser, but were met by a disciplined Town back line that wouldn't give up any chances.
Town U21s: Wilton, Fergus, Chippendale, Robinson, Steele, Clarke, White, Patience, Haswell, Barker, Hutton
Subs: Dobson, Myers, Mason, Gosling, Noon
Harrogate Railway: Latimer, Caufield, Ferguson, Swale, McCrum, Fitzgerald, Jordan, Lancaster, Sykes, Shields, Greenway
Subs: Boyd, Testagerish, Heeley, Newsome