Williams waved goodbye to international rugby in December with a try at the death against Australia while his final RBS 6 Nations match came against Ireland in March 2011.
But his club farewell topped both those for drama as five minutes from time Williams wriggled through two Leinster defenders to touch down for his second try and give Dan Biggar a conversion to win.
The cool-headed 22-year-old, who has never played in the RBS 6 Nations despite owning nine caps for Wales, slotted the kick from the narrowest of angles to make it 31-30.
Williams, 35, is in line to play for the Barbarians against Wales this Saturday but ahead of joining up with the star-studded scratch side he praised his teammates for helping him add a fourth Celtic League title to go with his two Grand Slams and the IRB Player of the Year from 2008.
"I enjoy success of course like anybody else," said Williams. "The one you remember is the latest one and this for me is a great way for me to finish.
"I am very proud of the fact that I am associated with the Ospreys. We have worked very hard this season, we have had our ups and downs and there has been a lot of change in the ranks, with a lot of players leaving the region.
"For us to stick at it the way we have this season it's a compliment to the guys. I will never forget this day."