Lappi fends off serial winner Ogier to lead in Mexico
Tanak had led overnight after winning the opening two stages but lost power on Friday's opening stage, known as El Chocolate.
"Turbo," said Tanak from the road. "There is a turbo in the car, but it's just dead."
Lappi, a Finn who drives for Hyundai, grabbed the race lead as Tanak limped in 7mins 47sec behind.
Frenchman Ogier, in a Toyota, who has won the rally six times, took the next stage but the Finn hit back to take the morning's final stage by 0.6sec and stretch his lead to 1.4sec.
"Seb has won this rally so many times and we can match his pace, so I need to be very pleased with that," said Lappi.
In the afternoon back-to-back stage wins in Las Minas and Las Dunas gave Lappi some breathing space, and he ended the day 5.3sec up on Ogier who took the Distrito Leon super special.
"I am a bit surprised, but I take it as it is," Lappi told wrc.com.
"This was probably one of the best days of my career.
"I always hoped that I could fight at the top, but to be leading and fighting against Seb was never in my mind. I didn't really think about how this day would go, but I was just confident that our pace would be good."
Welshman Elfyn Evans was third in a Toyota at 24.8sec.
Reigning champion Kalle Rovanpera, who trails Tanak by three points in the world rally championship standings after two events, ended the second day in fifth after suffering mechanical problems following a big slide at the end of the opening stage.
Tanak goes into Saturday's stages 14 minutes adrift after a nightmare time for the M-Sport Ford team.
Ford's Frenchman Pierre-Louis Loubet hit a rock on stage three.
Racing was briefly stopped on the stage after private driver Jourdan Serderidis, 59, in the third Ford, stopped, facing the wrong way, in the middle of the road.
Tanak can still pick up bonus points on Sunday's Power Stage.
Japanese driver Takamoto Katsuta went off the road and down a steep embankment in his Toyota on stage five - no way to celebrate his 30th birthday.