The sponsorship will officially begin when the football season starts on August 4 and has been designed to support the three divisions of SFL, which hold 30 clubs throughout Scotland.
Roger White, AG Barr's chief executive, said: "The passion and commitment shown in Scotland towards football is inspiring and a great fit for Irn Bru. We're looking forward to supporting the league and its member clubs in creative ways, working innovatively to support the game and connect with fans. This represents our biggest ever investment in sponsorship."
David Longmuir, chief executive of the Scottish Football League, said that the deal brought together two of Scotland's most famous brands.
"I am proud and delighted to welcome one of Scotland's best loved and most iconic brands to the SFL family. Irn Bru and the Scottish Football League are historic brands with powerful roots and relationships in communities throughout Scotland."