The Demons, who twice fell 20 points behind after halftime, edged closer to a top-two spot with their 20.10 (130) to 15.8 (98) victory in a classic contest at the MCG.
Former defender Petty (six goals) and young gun van Rooyen (four) fired as the key targets in an attacking mix that gave Simon Goodwin food for thought as he ponders axed recruit Brodie Grundy's future role in the side.
Jake Melksham also kicked four majors, including the goal that marked the sixth lead change in a see-sawing contest and put the Demons in front for the final time midway through the last quarter.
They finished far stronger than Richmond, kicking the last six goals of the game to post their highest score since round seven and settle a gripping battle in front of 52,294 fans.
Melbourne's Jack Viney (32 disposals, seven clearances), Christian Petracca (29, eight) and Max Gawn (28, 11) were outstanding.
Captain Gawn, who also had 40 hit-outs and 22 contested possessions, was particularly influential when the game was on the line in the last quarter.
The Demons remain in fourth spot on the ladder but moved closer to the top three after Collingwood, Port Adelaide and Brisbane all lost in round 20.
Richmond would have climbed into the top eight if they had won, and were left kicking themselves for letting their lead slip.
Tim Taranto (24 disposals), Jacob Hopper (23) and Shai Bolton (25) all fought hard in a losing battle, while Tigers superstar Dustin Martin kicked 3.2 from 21 disposals and had 11 score involvements.
Martin booted two majors in the third quarter, including one from the centre square, as Richmond surged ahead in slippery conditions.
They looked likely winners when Martin's long-range shot sailed through at the six-minute mark of the third term, but the lead had evaporated by three-quarter time.
The Demons kicked five of the next six goals and added another 6.4 to 2.0 in the final term.
Noah Balta's goal 10 minutes into the last quarter had put Richmond in front but they were no match for Melbourne when it mattered most.