Due to the 2012–13 NHL lockout, Gunnarsson was released by the Leafs in order to playout the season with his hometown team Örebro HK. After the lockout ended, Gunnarsson returned to North America and continued the season with the Toronto Maple Leafs. However, his time in the lineup was shortlived as he underwent treatment to rehabilitate a hip injury after playing in seven games. Gunnarsson was cleared to play for the Leafs prior to the 2013–14 season and made their opening lineup. That season would prove to be his last with the Maple Leafs, as on 28 June 2014, Gunnarsson and fourth-round draft pick in the 2014 NHL Entry Draft were traded to the St. Louis Blues in exchange for defenceman Roman Polák. He underwent hip surgery during the offseason and was medically cleared to play on 14 October 2014.