World Cup 2010 - France scrape past Costa Rica
The hosts made a bright start to the match, with Ribery and French captain Patrice Evra in particularly menacing mood on the left wing.
Ribery almost released Anelka through on goal in just the third minute, but the Chelsea striker was marginally offside, before playing a clever reverse ball just too far ahead of Yoann Gourcuff in the Coast Rican box a minute later.
However, Costa Rica soon made the hosts pay for their profligacy, scoring the opening goal in the 11th minute with their first shot of the match.
Carlos Hernandez received the ball deep in the French half, and was given far too much space to advance towards edge of the area and line up a shot.
The Australian-based midfielder steadied himself, before firing a low, right-footed shot inside Steve Mandanda's right post to give Costa Rica the lead, and silencing the 40,000-strong crowd in Lens.
The goal was a sucker punch for the French, but they had the ball in the back of the net themselves just four minutes later.
Ribery cut inside from the left before unleashing a fierce low shot from the edge of the area, which Keylor Navas could only parry into the path of Gourcuff.
The Bordeaux midfielder duly slotted the ball into the empty net, but the French celebrations were short-lived as the linesman had immediately, and correctly, flagged for offside.
French fans didn't have long to wait for an equaliser though, as Costa Rica finally succumbed to the rising French pressure in the 22nd minute.
The relentless Ribery broke again down the left wing, and Douglas Sequeira could only divert the Frenchman's low cross into his own net.
If the home fans thought that the goal would open the floodgates for their star-studded strikers, they were soon given food for thought as the crossbar denied Costa Rica the lead again just ten minutes later.
The visitors' 24-year-old captain Bryan Ruiz rose above William Gallas to connect with a looping corner, and thundered his header against the crossbar.
However, the French rallied again, and came close to taking the lead themselves on the stroke of half time, as Ribery latched on to Anelka's clever header over the defence and forced a fine save from Navas in the Costa Rican goal.
France emerged for the second half more solid and organised, and with the host of personnel changes now obligatory in international friendlies.
The home side continued to push for a goal, but Thierry Henry (on for Anelka) and Gourcuff both failed to beat Navas with a number of clear-cut chances in front of goal.
France were repeatedly frustrated until the 82nd minute, when two substitutes combined to finally provide the decisive finish that France had consistently failed to find in the final third.
Valbuena took a second to pick his spot, before powering a right-footed shot inside Navas's right-hand post in a mirror-image of the Costa Rican goal.
France held on comfortably to seal a deserved win, but will ultimately be left pondering how it took them 82 minutes to take a lead against a Costa Rican side ranked 42nd in the world.
However, the contributions from Ribery, Valbuena, and Diaby will be enough to give French manager Raymond Domenech some considerable comfort ahead of Les Blues' next friendly against Tunisia, on Sunday.