Petacchi just edged Cavendish in a battle for the finish line, in a victory which was only confirmed by the jury after viewing video footage.
The British rider tried to overtake Petacchi on the right before being forced to try on the left. Italy's Manuel Belletti finished third after the longest stage, raced under blazing sunshine over 244km.
It was the 22nd Giro success for 37-year-old Petacchi, whose five wins in the 2007 race were scrapped after a decision by the Court of Arbitration for Sport (CAS) following a positive test for salbutamol.
Petacchi won two stages of the Giro last year and the green jersey for the points standings. His previous success was in 2009.
Germany's Sebastian Lang led for most of the race holding a 19-minute advantage after 82km. But the former German time-trial champion was caught 26km from the line.
Monday's third stage is a 173km ride between Reggio Emilia and Rapallo.
Results from the second stage of the Giro d'Italia, a 244-km (151-mile) stage from Alba to Parma:
1. Alessandro Petacchi, Italy, Lampre, 5 hours, 45 minutes, 40 seconds.
2. Mark Cavendish, Britain, HTC-Highroad, same time.
3. Manuel Belletti, Italy, Colnago, same time.
4. Roberto Ferrari, Italy, Androni Giocattoli, same time.
5. Borut Bozic, Slovenia, Vacansoleil-DCM, same time.
6. Davide Appollonio, Italy, Sky, same time.
7. Tyler Farrar, United States, Garmin-Cervelo, same time.
8. Robbie McEwen, Australia, RadioShack, same time.
9. Wouter Weylandt, Belgium, Leopard, same time.
10. Matteo Montaguti, Italy, La Mondiale, same time. ^Overall Leaders= ^(After 1 of 21 stages)=
1. Mark Cavendish, Britain, HTC-Highroad, 6 hours, 6 minutes, 27 seconds.
2. Kanstantsin Sivtsov, Belarus, HTC-Highroad, 12 second behind.
3. Craig Lewis, United States, HTC-Highroad, same time.
4. Marco Pinotti, Italy, HTC Highroad, same time.
5. Lars Ytting Bak, Denmark, HTC-Highroad, same time.
6. Alessandro Petacchi, Italy, Lampre, :16.
7. Robbie McEwen, Australia, RadioShack, :22.
8. Fumiyuki Beppu, Japan, RadioShack, same time.
9. Yaroslav Popovych, Ukraine, RadioShack, same time.
10. Tiago Machado, Portugal, RadioShack, same time.