The 29-year-old spent the latter half of last season on loan at McDiarmid Park from Coventry City.
He signed for Hearts after being released by the English League One outfit but made only nine appearances for Saints' Premiership rivals.
The former Berwick Rangers, Dundee United and Peterborough United winger has signed an 18-month contract.
Swanson had been released by Hearts on Monday and was signed by Saints as a replacement for Michael O'Halloran, who had been sold to Rangers the same day.
He made 12 appearances in his previous spell with the Perth club, scoring twice.
Winger Danny Swanson has returned to St Johnstone after a frustrating five months with Hearts.