The Omega Pharma-QuickStep rider won the 160km route from Camel Race Track to Al Khor Corniche, which is the longest of the race.
The 27-year-old from the Isle of Man, who quit Team Sky late last year, beat Holland's Barry Markus and Italian Andrea Guardini in the battle of the sprinters to claim the Golden Jersey after the peloton reeled in the leading breakaway group by 146kms.
Cavendish stayed clear of a crash in the closing stages to cross ahead of Vacansoleil-Dcm racer Markus with Astana Pro Team's Guardini in third.
The victory, and the accompanying 10-second time bonus, saw Cavendish take the overall lead by two seconds from American Brent Bookwalter of BMC Racing.
The fifth stage of the Tour of Qatar runs over 154km from Al Zubara Fort to Madinat Al Shamal.