Sonko is seen shedding tears as he sings along to a popular local gospel song.
High Court Judge Justice Msagha Mbogholi also ordered the two petitioners Japheth Muroko and Zacheus Okoth to pay Mr Sonko a total of Sh5 million.
In a video circulated on social media, Sonko is seen weeping as he sings along to a popular local gospel song on his mobile phone in an apparent show of gratitude to God for granting him the win in his court case.
The ruling came a few hours after the petitioner Muroko claimed that he and his family had received threats to life.
Mr Muroko, through his lawyer Anthony Oluoch told the court that he needed the day to record statements at Kilimani Police Station.
Muroko and Okoth had challenged Sonko's win over claims of irregularities and bribery among other allegations.