He continued to focus on road running in 2004, beginning with a run of 59:56 minutes at the Lisbon Half Marathon for fourth place on the downhill course.[9] Next came the London Marathon, where he finished third behind Evans Rutto and Sammy Korir and set a personal best of 2:07:02 despite slipping and banging his head mid-race.[10] He competed at his first Olympics at the 2004 Athens Games but failed to match his previous global form and finished in eleventh place in the men's marathon.[11] A groin injury in the run-up to the competition and Gharib reflected that he had pushed himself too much in training during the two weeks before the race.[12]
He repeated his approach to the season in 2005 by starting at the Lisbon Half Marathon and he finished sixth on this occasion.[13] He ran sub-2:08 at the London Marathon for a second time and improved one place from the previous year, finishing as runner-up behind Martin Lel.[14] His focus of the year was a defence of his title at the 2005 World Championships in Athletics. He returned home to Morocco and trained at altitude in the Atlas Mountains region. The move proved fruitful as, in spite of a sleepless night and stomach pains during the competition, he won the world championship marathon with an eleven-second margin over runner-up Christopher Isengwe.[12] This made him only the second runner ever to retain the world marathon title, after Spaniard Abel Antón.[15]
With no major competition to work towards in 2006, he focused on competing on the circuit. He finished the London Marathon in a time of 2:08:45 – the third fastest run of his career at that point – but this was only enough for eighth in a fast race which saw him beaten by compatriot Hicham Chatt.[16] After a fourth-place finish at the Great North Run, his next marathon race came at the Fukuoka Marathon in Japan. Gharib came close to a career best, crossing the line in 2:07:19, and took third place on the podium behind Haile Gebrselassie and Dmytro Baranovskyy.[17]
Olympic silver
He had his third sub-2:08 clocking at the London Marathon in 2007, recording 2:07:54 for fourth place. At the Chicago Marathon later that year he came close to victory but a photo finish between Gharib and Patrick Ivuti resulted in the Moroccan being declared the runner-up.[18] Gharib won the silver medal in the 2008 Summer Olympics marathon held in Beijing, China, giving him his first Olympic medal. Gharib improved his personal best to 2:05:27 at the 2009 London Marathon, finishing in third place.[19] He also finished in third place at the 2009 NYC Marathon.[20]
Running in the 2010 London Marathon, he had to endure stomach problems but still made the podium, coming home in another third-place finish with a time of 2:06:55.[21] He took third place at the Great North Run half marathon in September.[22] He was victorious at the Fukuoka Marathon in December, completing a solo run on the hot course to win in a time of 2:08:24.[23] The 2011 London Marathon was a particularly fast race and his time of 2:08:26 left him in sixth and almost four minutes behind winner Emmanuel Mutai.[24]