The 30-year-old midfielder moved to McDiarmid Park for a second spell in February 2016 after a frustrating five months with Hearts.
He has scored 14 goals in 48 appearances since then, having netted twice while on loan in 2015.
"The pull of Hibernian was too much for me," said Swanson.
"It's always been an ambition of mine to play for the club and I am looking forward to this new challenge and to help achieve their goals back in the Premiership."
The Championship winners are yet to reveal details of the contract agreed with the former Dundee United, Peterborough and Coventry City player.
Saints offered the midfielder new terms, with Swanson adding: "The decision to leave St Johnstone has been a difficult one for me. I've felt settled at the Saints and really enjoyed my football, and my period at the club has been the most enjoyable and satisfying time of my career.
"So, it goes without saying, my decision to leave McDiarmid Park was not taken lightly.
"I want to thank the manager, Tommy Wright, who has supported me in so many ways, on and off the field.
"His trust in me on the football park allowed me to flourish. The way he treated me like an adult off the park also helped me to mature and develop as a person.
"Now that we are in the top six yet again, which is yet another fine achievement, for the next five games it's my focus to make sure I play my part in helping St Johnstone qualify for a European place."
Saints are currently fourth in the top flight, five points ahead of Hearts in the race for the final Europa League spot.
Asked what Swanson would bring to his Hibs team, head coach Neil Lennon told his club website: "Goals from midfield, hopefully, creativity,
"He's had a great season, into double figures.
"I think he sees a pass, he's a fit lad, he crosses the ball well. And, whenever I have seen him play for St Johnstone, he has probably been their best player and more likely to create something.
"And, allied to that, he is a Leith boy. He gets the club and that's always important as well."
Find all the latest football transfers on our dedicated page.
Danny Swanson has confirmed that he is leaving St Johnstone to join Hibernian, saying he could not resist the lure of his boyhood favourites.