The home side struggled without leading scorer Grant Holt and Cheltenham grew in confidence as the game went on.
John Ward's side took the lead midway when Grant McCann picked out Melligan in the box and, despite being surrounded by four defenders, the former Wolves midfielder toe poked the ball home.
With Rochdale pressing for an equaliser Martin Devaney broke away and his cross was finished at the far post by substitute Wilson.
A hotly disputed penalty won and converted by home skipper Gary Jones sparked a grand stand finish and some unsavoury scenes at the side of the pitch as a visiting fan appeared to striker Rochdale defender Wayne Evans.
Despite the late drama Cheltenham held on for the first win since August.