St. Petersburg, Russia — Lionel Messi and Argentina finally got things going at the World Cup.

Messi scored an exquisite 14th-minute goal to give the two-time champions the lead in a must-win game against Nigeria on Tuesday, but it wasn’t until Marcos Rojo’s 86th-minute strike that Argentina was assured of a place in the round of 16 with a 2-1 victory.

Victor Moses scored from the penalty spot in the 51st minute for Nigeria, putting Argentina in danger of being eliminated without winning a match in Russia.

It took an unlikely goal by Rojo – a center back – to save Argentina with a cushioned volley into the corner.

The win gave the Argentines second place in Group D and allowed the soccer-mad nation to forget about the 3-0 loss to Croatia last week that sparked days of soul-searching within the squad and back home.

Argentina will play France in the last 16 in Kazan on Saturday, keeping alive Messi’s quest for a first world title. He might have retired from international soccer for a second time – and for good this time – if it wasn’t for Rojo’s goal.

Messi’s teammates poured off the bench to celebrate with him after the final whistle, forming a circle around him. Messi exchanged a long hug with teammate Javier Mascherano, who clinched him tightly.

While Gonzalo Higuain cried nearby, Messi clinched his fist as he turned toward the Argentina fans.

“I knew that God is with us,” Messi said, “and he wouldn’t let us get eliminated.”

Messi’s name adorned the back of most of the Argentina jerseys that dominated St. Petersburg ahead of the game, and received the biggest roar when the teams were read out.

He kicked the ball out of play with his first touch, was tackled with his next, but then he started to put on a show.

Messi’s 65th international goal owed as much to Ever Banega’s long, driven pass over the defense as the forward’s exquisite control on his left thigh, another touch with his left foot, and then a cool right-footed finish into the corner. As Messi fell to his knees and pointed his fingers upward in celebration before being mobbed by teammates, Argentina great Diego Maradona – sitting in a corporate box inside the stadium – placed him arms on opposite shoulders and looked to the sky.

Messi, who later hit the post off a free kick, and the recalled Banega ran the game in the first half for Argentina. The team’s biggest problems arose whenever Mascherano lost possession in front of his own defense.

And it was Mascherano who gave away the penalty with a pull on Leon Balogun at a 49th-minute corner. Moses converted – and marked the goal with a somersault – to put Nigeria back in control of the race for second place in the group.

Argentina was facing finishing a World Cup without a win for the first time since 1934, but instead they are headed to the knockout stage.

More World Cup matches

Croatia 2, Iceland 1: At Rostov-on-Don, fielding a side filled with reserves, Croatia ended Iceland’s first ever World Cup run. Milan Badelj crashed a volley against the bar, and moments later scored for Croatia in the 53th minute, sprinting into the area to fire a bouncing shot past goalkeeper Hannes Halldorsson.

Peru 2, Australia 0: At Sochi, already-eliminated Peru ended Australia’s hopes of advancing to the knockout round. The Australians had to beat Peru and hope Denmark lost to France in the other Group C match.

France 0, Denmark 0: At Moscow, the slow-paced game was the first scoreless draw of the tournament. But it advanced both teams to the round of 16 unbeaten, with the bonus of no players suspended and no serious injuries. The draw would always have ensured that outcome, and became inevitable in the second half. Events elsewhere in Group C made this game all but irrelevant.

World Cup

Tuesday’s results

France 0, Denmark 0

Peru 2, Australia 0

Argentina 2, Nigeria 1

Croatia 2, Iceland 1

Wednesday’s games

Mexico vs. Sweden, 10 a.m. (Fox)

South Korea vs. Germany, 10 a.m. (FS1)

Serbia vs. Brazil, 2 p.m. (Fox)

Switzerland vs. Costa Rica, 2 p.m. (FS1)

Thursday’s games

Japan vs. Poland, 10 a.m. (FS1)

Senegal vs. Colombia, 10 a.m. (Fox)

Panama vs. Tunisia, 2 p.m. (FS1)

England vs. Belgium, 2 p.m. (Fox)