looked down and out when Victor Moses was sent off on 68 minutes for picking up a second yellow card for diving.
However, Diego Costa sensationally levelled for the 10 men on 77 minutes, only for Ramsey to hit an instant reply for the Gunners just 60 seconds later after a wonderful cross from substitute Olivier Giroud.
The victory ends a disappointing league season on a high for Arsene Wenger, who has now won the FA Cup a record seven times as Arsenal boss - although he is yet to announce whether he is staying on as manager next season.
All the pre-match talk surrounding this clash revolved around Arsenal's injury issues at the heart of their defence.
With Laurent Koscielny suspended and Gabriel and Shkodran Mustafi missing out through injury, Wenger had to field a makeshift back three of Per Mertesacker, who was making his first start in 13 months, alongside Rob Holding and Nacho Monreal.
It was thought that Chelsea would pressurise the Gunners backline early on - but it was Arsenal that looked the more eager to force the running and they were in front inside four minutes, albeit in controversial circumstances.
David Luiz's clearance was blocked by Sanchez, who used his hands to divert the ball into his path. The Chilean then tried to knock the ball into the path of Ramsey, but he was in an offside position.
With the Chelsea players appealing for handball and offside, Sanchez carried on his run and got there ahead of Ramsey before sliding an effort past Thibaut Courtois. The linesman had flagged for offside but referee Anthony Taylor overruled his assistant after a 30-second deliberation and Arsenal's players celebrated wildly.
Chelsea looked shell-shocked and very leggy as Arsenal swarmed around them at every opportunity.
The Gunners were afforded considerable space in the final third, with Danny Welbeck's movement causing Gary Cahill and David Luiz untold amounts of problems. Mesut Ozil took advantage of the huge gaps in the Chelsea backline on 16 minutes but his chipped effort was back-heeled off the line by Cahill.
The Arsenal pressure was relentless, but they could not find the second goal their dominance deserved. Ozil's corner was headed onto the post by Welbeck on 19 minutes and somehow Ramsey amazingly followed suit from three yards out - although the angle was tight.
Chelsea continued to live dangerously and Welbeck sprinted in behind on the half-hour, and his effort from a tight angle beat Courtois but not Cahill, who scrambled it off the line.
Although regarded as one of the most resolute teams in the Premier League, Antonio Conte's men had lost five of their six games when behind at half-time this season. They came out with a bit more swagger after the break, with Moses stinging David Ospina's gloves with an effort from 15 yards and Pedro curling wide from the edge of the box on 59 minutes.
With Chelsea looking increasingly dangerous, their task was made tougher as Moses had a moment to forget on the Wembley turf.
Already on a yellow card, the wing-back, whose journey this season has been a heartwarming tale, theatrically and laughably went down in the penalty area under no contact from an Alex Oxlade-Chamberlain tackle.
Referee Taylor spotted it, which meant Moses had to take a long walk of shame in front of the watching world.
That looked to be the end of Chelsea's season but Costa had other ideas. The striker turned inside the area on 77 minutes and fired a low effort past Ospina, which stunned the Arsenal end of the stadium.
They would have been forgiven for thinking 'same old Arsenal' but their team gave one final push. Aided by Wenger's substitution of bringing on Giroud for Welbeck, they conjured up a moment of magic to win the game.
Giroud darted in behind Luiz and Cahill and chipped an outstanding ball into Ramsey, who thumped a header into the net from 12 yards.
Arsenal pushed for the third late on and hit a post through Ozil, while Costa nearly grabbed another unlikely equaliser but Ospina made a point-blank save.
The final whistle brought huge cheers from the Arsenal end and a double fist pump from Wenger.
Arsenal end a problematic season on a high.