The Premiership outfit were made to battle all the way by the Lowland League champions before breaking the hosts’ resistance after the break.
Erwin made the breakthrough in the 63rd minute before summer signing Ndjoli’s brace gave the scoreline a more respectable look.
Killie started at a furious pace and could have been out of sight by half-time. Kris Boyd had the ball in the net in just the second minute but was penalised for a push on Blair Tolmie.
But, after withstanding the onslaught, Spartans settled and managed to break out of Kilmarnock’s stranglehold.
The Edinburgh side pushed men forward when they could and, with another Boyd shot saved by Scott Costello, they reached the interval still level.
The Premiership men finally broke the deadlock soon after the hour. Iain Wilson’s cross from deep ricocheted kindly for Erwin, and the striker drilled in from eight yards.
Summer signing Ndjoli – a 78th-minute substitute – then hammered in a low cross to make sure of the points and added gloss to the scoreline when he bundled in after Boyd chested the ball into his path.