Williams stunned the European champions with the perfect parting gift that helped decide the fate of the RaboDirect Pro12 Final.
The 35-year-old, who retires after a last hoorah with the Barbarians next week, scored twice including a 78th-minute try that set up Dan Biggar, who held his nerve to land the match-winning kick from wide.
It capped an astonishing career and a remarkable turnaround by the Ospreys who were in dire straits just three months when they appointed Steve Tandy from the back-room to head coach.
Yet they came to the home of the Heineken Cup holders, and somehow conspired to dig out a dramatic win and their fourth Pro12 title.
Williams said: “This win says so much about the team. We’ve been through some difficult times but what a way to hit back. We stuck at it right to the end and got what we deserved.
“I knew this day was coming and it was pretty emotional but scoring a couple of tries was a great way to go out. I’m going to miss the boys and the camaraderie but it’s not as if I am passing away. I’ll still be around, even if I’m not playing.”
Williams will take up a role as club ambassador from next season and he provided a touch of class here in a feisty contest that erupted at half-time.
Leinster may have dominated the Heineken Cup but have now only once won their domestic title in nine years.
Tries from Isa Nacewa and Sean Cronin and 15 points by Jonathan Sexton looked to have put the Irish on track for an historic double before the first half ended in controversy.
Leinster had prop Heinke Van Der Merwe binned and were twice warned by referee Romain Poite for collapsing a series of eight scrums scrums before getting a crucial decision in injury time.
That had the Ospreys management jumping in frustration on the sidelines and sparked a brawl between players as both teams left the field at half-time.
Ashley Beck hit back early in the second half and despite Nacewa’s second, Nathan White was saw the yellow card and Williams wriggled through two defenders to settle a thrilling final.