Ethiopian Deriba Merga had led the field for much of the race but faded at the end to wind up fourth.
Several of the favourites failed to cope with the sweltering Beijing heat, among them defending Olympic champion Stefano Baldini of Italy.
|The marthon course took runners past some of Beijing's most famous sights [GALLO/GETTY]
Baldini fell well behind early on as he failed to find the spark that took him to gold in Athens four years ago
The Italian eventually finished 12th.
World record holder, Ethiopia's Haile Gebrselassie, opted out of the Beijing marathon earlier this year citing concerns about Beijing's notorious air pollution.
But an overnight thunderstorm had cleared the air by Sunday morning, providing a clear blue sky for the final day of the Beijing games.
The race saw some clear leaders pull away from the pack early on, and by the halfway mark, eight were grouped at the front, led by Eritrean Yonas Kifle.
At 30 kilometres the frontrunners had dwindled to three - Wanjiru, Merga and Gharib – while Kenya's Luke Kibet, the reigning world champion, fell back after having stayed with the leaders through the early stages.
Kibet eventually pulled out of the race, saying later he had a stomach problem.
By the final two kilometres Wanjiru had opened up an unassailable 18 second lead, entering the Bird's Nest stadium to a standing ovation from the capacity crowd.