City have made an impressive unbeaten start to this season, taking six points from four league games.
The club have also announced the departure of football consultant Sammy Yu, after only nine months in the role.
Speaking after Birmingham's 3-1 defeat to West Brom on Saturday, McLeish said: "It is a bitter-sweet day given the fact we have lost. But it is great to sign the contract at last.
"I look forward to the continued development of the club and the team. I don't want to talk about the details, they are private, but the club have now got better security. All parties are happy, that is the main thing."
But Sammy Yu, the former Hong Kong coach who played an important role in helping tycoon Carson Yeung take over the Blues, has severed his links with the club with immediate effect.
Yu's departure follows criticism of his role in overseeing Birmingham's pre-season tour of China and Hong Kong, which reportedly came under fire from players for its gruelling itinerary and facilities.
Great news, hopefully that can be a little bit extra and push the players on MackemBluenose "I think the time is right for me to step down," Yu told the Birmingham Mail.
"After four years being part of the whole deal, from the beginning, I have done my bit.
"It's time to release myself and I wish Birmingham City the best for the future. To be part of the club's history in a very important era is a highlight of my life."
Yu, who was initially appointed as assistant to McLeish before being moving into his role as consultant, denied that a rift with the Scot was to blame for his departure.
"I had no problem with Alex. It was a bit naive for anyone to think that when I first came in it was to take his job," added Yu.
Former Rangers boss McLeish has overseen Birmingham's re-establishment in the top flight, utilising the funds made available to him by Yeung to build a competitive side.
McLeish has been keen for some time to extend a contract that was due to expire next summer.
In referring to his new deal, a statement on the club website said: "Club president Carson Yeung has rewarded that success with a new improved deal for McLeish, after giving the green light for him to bring in Ben Foster, Nikola Zigic, Enric Valles, Matt Derbyshire, Alexander Hleb, Martin Jiranek and Jean Beausejour in the August transfer window.
"That followed the acquisitions of Craig Gardner and Michel in January."