© Getty Images
The game started off slowly, and Jack Clisby came closest for the home side early on but a save from Eugene Galekovic denied the left-back.
Shortly after the half-hour mark, Sanchez put Adelaide in front with a tidy finish after Sergio Cirio put him through.
Cirio then had a chance himself but his effort was kept out by Tando Velaphi.
Melbourne responded seven minutes into the second half, when Baharudin slotted home from the back post after Aaron Mooy's cross.
Just three minutes later, Kennedy headed in his first for Melbourne since joining in November, after Robert Koren picked out the Australian international.
The home side began to dominate play, with Kennedy going close once more, forcing a save from Galekovic.
Ramsay clinched victory in the 87th minute, with a close-range finish following Massimo Murdocca's cross.
The three points puts Melbourne up into sixth, while Adelaide, who could have gone top with a win, remain third.