Odion Ighalo gave Nigeria a 19th-minute lead on Saturday but Cameroon hit back with two goals in quick succession before the break from Stephane Bahoken and Clinton Njie.
Ighalo levelled again for Nigeria in the 63rd minute amid suspicions of offside before Alex Iwobi snatched the winner for the jubilant Super Eagles three minutes later.
Both teams finished second in their groups and had not been in the best of form and it showed with an abundance of defensive mistakes, but there was also much to admire in an end-to-end match.
It was a scrappy opening with misplaced passes by both sides until Nigeria went ahead.
Cameroon’s defence failed to deal with a free kick into the area and Kenneth Omeruo found Ighalo who reacted quickly and scored with a shot that was deflected into the net.
The game turned dramatically before halftime as Cameroon, who had not scored in their previous two games, struck twice in three minutes.
Christian Bassogog wriggled past his marker on the right and sent a perfect cross into the area, leaving Bahoken with the formality of turning the ball into the net in the 41st minute.
Nigeria had barely time to recover when Cameroon struck again with Bahoken turning provider as he flicked the ball on to Clinton Njie who raced past Olaoluwa Aina and drilled the ball into the net.
Goalkeeper Victor Akyepi made a desperate last-ditch save to prevent a Nigeria own-goal early in the second half before the game took another twist.
Nigeria levelled in the 61st minute when Ahmed Musa chested the ball into the path of Ighalo to volley home.
Three minutes later, Ighalo turned provider as he set up Iwobi who beat Andre Onana with a calm finish to set off wild celebrations among the Nigerian players, officials and media.
SOURCE: Reuters news agency