Bluebirds winger Nathaniel Mendez-Laing hit the post on a frustrating night for Neil Warnock's men, before the game was eventually settled in the dying embers when Grealish let fly with a spectacular first-time volley from the edge of the box to hand Villa all three points.
Victory for the Villans will likely ignite faint hopes of a late push for an automatic promotion spot, while defeat for City now leaves them outside of the top two thanks to Fulham picking up a victory against Reading down south.
Steven Bruce's charges started the game with positive intent and they almost carved out a chance inside the opening minutes, Grealish feeding Lewis Grabban in behind, only for the striker to fire into the side-netting from a tight angle.
Cardiff appeared happy to work on the counter and their patience almost paid dividends when Mendez-Laing robbed Axel Tuanzebe before setting up a neat counter with Kenneth Zohore, although the move's initiator was to be denied by the far post after drilling an effort beyond the reach of Sam Johnstone.
The hosts held plenty of the ball in the first half, but they had to call on some crucial defending when Glenn Whelan deflected a shot towards his own goal, leaving Ahmed Elmohamady to make a memorable block on the line.
City finished the half strongly and they should have taken a lead into the break when Whelan turned a header the wrong way inside the area, where Johnstone leapt to the rescue to keep out an own goal. The keeper then went one better by responding to Callum Paterson's quick-fire rebound with another standout save down low.
The Villans started the second period with more intent and they might just have won themselves a penalty shortly after the restart, but the referee waved play on despite a rather suspect challenge from Joe Bennett on winger Robert Snodgrass.
Villa's next chance arrived with just over 20 minutes remaining when Grabban found Conor Hourihane with an exquisite through-ball, the midfielder somehow prodding wide of the target despite being left one-on-one with an advancing Etheridge.
It looked as though the teams might have to settle for a point each, but Grealish had other ideas in the final few exchanges, the youngster profiting from Sean Morrison's tame clearance to smash home from the edge of the area and steal a last-gasp victory for the hosts.
A second defeat on the bounce for Cardiff now means that the Bluebirds will need to win their remaining game in hand over Fulham in order to retake second spot, but that contest comes against a tough Derby County side.
As for the Villans, Bruce and his men will be confident of wrapping up a spot in the playoffs come the end of the campaign, although this win might just inspire them towards making a late dash for a place in the top two.
ASTON VILLA (4-5-1): Johnstone; El Mohamady, Jedinak, Chester, Tuanzebe (Bree 26'); Bjarnason, Hourihane (Samba 88'), Adomah (Kodjia 60'), Grealish, Snodgrass; Grabban
CARDIFF CITY (4-5-1): Etheridge; Peltier, Morrison, Bamba, Bennett; Paterson, Grujic, Gunnarsson, Mendez-Laing (Pilkington 90'), Hoilett (Ward 88'); Zohore (Madine 68')
body check tags ::