Goals from O'Brien on 71 minutes and Gregory on 75 minutes settled a hard-fought game in favour of hosts Millwall.
Chris Wilder's Northampton fought hard throughout and created some good chances of their own but were unable to find a goal.
It means the end of the Cobblers Johnstone's Paint Trophy hopes for another season but the recent upward progression of the team will hopefully continue at the weekend when Hartlepool United are the visitors to Sixfields.
Reaction: Chris Wilder shed few tears for his team's exit after the game, telling BBC Radio Northampton: "I'm not a lover of the competition. I think we play enough football, we've got the League Cup and the FA Cup."