The 24-year-old, who is currently number one in the International Cricket Council Twenty20 batting rankings, will be available for all 14 South Group games and a possible quarter-final.
Azam struck a century in Pakistan’s win over Leicestershire on Wednesday night and has scored 1,182 runs at an average of 53.72 in 29 T20s for his country.
He said: “I am looking forward to the new challenge that playing T20 cricket in England will bring.
“I have heard good things about Somerset from Azhar Ali and I want to play a part in the club winning matches.
“I know that Somerset get good support and I hope that I can give them something to cheer about this year.”
Andy Hurry, Somerset’s director of cricket, said: “To be able to sign a player of the calibre of Babar Azam is tremendously exciting. He is a proven performer at the very highest level and that is highlighted by the fact that he is the top rated international T20 batsman in the world.”