The 40-year-old previously topped the charts on Daft Punk's Get Lucky and Robin Thicke's Blurred Lines, with writing credits on both.
Happy, a feel-good pop song featured in the hit animation film Despicable Me 2, and comes with a 24 hour-long video.
It unseated last week's number one by X Factor star Sam Bailey.
Skyscraper switches places with Williams' hit to take second place in this week's countdown.
Continue reading the main story
Radio 1 Official Chart show logo
See the UK Top 40 singles chart
See the UK Top 40 albums chart
BBC Radio 1's Official Chart Show
The chart placing rounds off a successful comeback for Williams, as Blurred Lines and Get Lucky were named the two best-selling singles of 2013 at the beginning of this month.
Originally one half of the production duo, The Neptunes, Williams has received seven Grammy nominations including producer of the year (non-classical), two nominations for record of the year for Get Lucky and Blurred Lines and two album of the year nominations for Daft Punk's Random Access Memories and good kid, m.A.A.d city by Kendrick Lamar..Despicable Me 2 (Pharrell, Cee Lo Green)