Trailing at half-time in a match they had to win, the Super Eagles hit back with two goals inside five minutes through Martins, currently at German champions Wolfsburg, and Everton striker Aiyegbeni Yakubu.
Kenya levelled 12 minutes from full-time as they battled to finish third in Group B and clinch a place at the 2010 CAF African Cup of Nations only for Martins to score the winner on 83 minutes.
The Harambee Stars failed to clear a cross and the former Newcastle United striker spun before hooking the ball past goalkeeper Willis Ochieng to earn Nigeria a fourth FIFA World Cup appearance.
Nigeria finished with 12 points, Tunisia 11, Mozambique seven and Kenya three, the Super Eagles becaming the fourth country to qualify from the African Zone after South Africa (hosts), Ghana and Côte d'Ivoire.
Back in Nigeria, there was joy unrestrained. In the south-western city of Abeokuta, Nigeria fan Rasheed Sule said: "I saw fans crying tears of joy after Nigeria qualified. I never thought Nigerians love their country this much. It was simply amazing."
Another fan, Ahmed Shugaba said thousands of Nigerians defied pouring rain in Benin City to celebrate the Eagles' qualification. "It was a miracle. We still don't believe we have some how qualified for the World Cup. Not even the heavy rain could stop our celebrations."
"This has shown that there is a lot of talent in the team and we will see this at next year's World Cup," said former African Footballer of the Year Victor Ikpeba. "Mozambique also deserve our gratitude. They are a decent side and they will do very well at the Nations Cup in Angola."