Tries by Jono Crossan and Gordon Reid gave Ayr a 17-13 half-time lead.
Scott Sutherland, Cammy Taylor and Andrew Wilson touched down as Ayr turned in a strong display after the interval at Murrayfield.
The match doubled as a league fixture and the victory sees Ayr go level on points at the top with Currie.
Ayr skipper Damien Kelly was named man-of-the-match and said: “It’s a very proud moment, our first time in the cup final, our first win.
“We’ve got great team spirit. The boys all get on.
“We didn’t start that well; we didn’t really touch the ball in the first 30 minutes, but we just had belief that we could do it.”
In the Bowl event, North Berwick beat Strathmore 13-8, while Lasswade won the Shield, beating Greenock Wanderers 17-7.
In Premier One Glasgow Hawks went down 25-21 to Heriot’s at Goldenacre. The Hawks scores came from George Hunter and Kerr Gossman.
Duncan Weir kicked three penalties and added a conversion.
go ayr