It was built by the Bötzbergbahn, a joint venture of the Schweizerische Nordostbahn ("Swiss Northeast Railway") and the Schweizerische Centralbahn ("Swiss Central Railway"). Construction started in 1870 and it opened on 2 August 1875. It was taken over by the Swiss Federal Railways in 1902. It is now an important freight line connecting Germany and Italy via the Gotthard.
A proposal was made in 1836 to build a railway line from Zürich to Basel via Laufenburg but it suffered from lack of finance and opposition in Basel. The section between Zürich and Baden opened on 9 August 1847 by the Schweizerische Nordbahn ("Swiss North Railway"), which became known as the Spanisch-Brötli bahn ("Spanish bun railway"). The Aargau canton government proposed a continuation of the line via Brugg and the Bözberg Pass to Basel.
In 1858 the Schweizerische Centralbahn opened a line from Brugg to Olten, connecting to its Hauenstein line to Basel. At the same time the Zürich–Baden line (which by that time had been merged into the Schweizerische Nordostbahn) was extended to connect with the Centralbahn's line at Brugg. Construction of an alternative route, known as the Bötzbergbahn (BöB) began in 1870 and it was opened on 2 August 1875 through the Bözberg Pass from Pratteln to Brugg via the Frick valley and the 2,526-metre-long Bözberg Tunnel by a joint venture of the Centralbahn and the Nordostbahn. This line is 49 km long, about 8 kilometers shorter than the line via Olten. Trains on it used the Centralbahn between Basel and Pratteln and the Nordostbahn between Brugg and Zürich. The single-track line was built with a maximum grade of 1.4%.
In 1895 the section between Pratteln and Stein-Säckingen was duplicated. No further duplications were made until the Bözbergbahn was incorporated in the Swiss Federal Railways on 1 January 1902. In November 190?, the section from Stein-Säckingen to Frick was duplicated. In April 1905 this was followed by the duplication of the Schinznach-Dorf–Brugg section and finally in September 1905 duplication was completed on the section from Schinznach-Dorf through the tunnel to Effingen and Frick.
On 18 October 1926 the entire line from Pratteln to Brugg was electrified. Between Basel and Pratteln the Bözberg and Hauenstein lines share the same track. Congestion on this section was relieved by the opening of Adler Tunnel in 2003 between Liestal and Muttenz, which is now used by fast passenger trains.