The 22-year-old signed for the Swans from Arsenal in the summer of 2012, but was limited to two appearances last season through injury.
"It's great news," Bartley told Birmingham's official website. "As soon as my agent mentioned the move then I was all for it because this is a massive club with a massive fan base.
"I know the manager well and he's a really good young manager who matches the club's ambition."
Birmingham start the new Championship campaign against Watford at home on August 3.