The Qatari began the day second overall in his Red Bull buggy, 6m33s behind Peterhansel's X-raid Mini, but was in contention for honours on the Nazca-Arequipa stage throughout.
A final burst of speed at the end of the day gave him a second stage win of the 2013 event by 36s from Guerlain Chicherit's Astana buggy.
With Peterhansel third fastest over the 179 miles and 1m17s slower than Al-Attiyah, the Frenchman's lead is now a reduced 5m16s.
Former leader Carlos Sainz had already dropped to 10th after organisers reversed their decision to give him back the 20 minutes he lost on Sunday to a navigational problem.
And the Spaniard lost yet more time on Tuesday, his Red Bull buggy stopping several times, just as it had done the previous day.
There were also problems for Lucio Alvarez, third overnight. He spent a long period at a standstill, allowing fellow Toyota driver Giniel de Villiers and X-raid duo Leonid Novitskiy and Nani Roma to move into third, fourth and fifth respectively.
Robby Gordon began the day in 13th, but rolled his Hummer less than 20 miles into the timed section. Although unharmed, Gordon's hopes of a good result are gone, the Hummer still having not moved over two hours later.
Leading positions after stage four:
Pos Driver Team/Car Time/Gap
1. Stephane Peterhansel X-raid Mini 9h04m29s
2. Nasser Al-Attiyah Red Bull Buggy + 5m16s
3. Giniel de Villiers Imperial Toyota + 33m22s
4. Leonid Novitskiy X-raid Mini + 33m48s
5. Nani Roma X-raid Mini + 39m06s
6. Guerlain Chicherit SMG Buggy + 42m32s
7. Ronan Chabot SMG Buggy + 59m30s
8. Bernard Errandonea SMG Buggy + 1h04m54s
9. Boris Gadasin G-Force Nissan + 1h22m07s
10. Pascal Thomasse MD Buggy + 1h23m56s
Leading stage four times:
1. Nasser Al-Attiyah Red Bull Buggy 3h28m46s
2. Guerlain Chicherit SMG Buggy + 36s
3. Stephane Peterhansel X-raid Mini + 1m17s
4. Giniel de Villiers Imperial Toyota + 4m17s
5. Nani Roma X-raid Mini + 7m27s
6. Leonid Novitskiy X-raid Mini + 13m55s
7. Nunzio Coffaro Azimut Toyota + 20m45s
8. Ronan Chabot SMG Buggy + 21m07s
9. Pascal Thomasse MD Buggy + 24m37s
10. Bernard Errandonea SMG Buggy + 27m39s