Following the collapse of the Wiltshire & Gloucestershire Railway, a joint scheme of the Midland and Great Western Railways to build a line from Christian Malford, between Chippenham and Swindon, via Malmesbury, Tetbury and Nailsworth to Stroud, the Malmesbury Railway was launched by the people of the town to provide at least local access to their town. The Malmesbury Railway was incorporated by an Act of 25 July 1872 to build a line, 6 mi. 43. ch long, from Dauntsey on the main line to Malmesbury. The station at Malmesbury was reached by means of a tunnel, which is thought to have been part of the abandoned Wiltshire & Gloucestershire scheme. Following a protracted legal dispute with the contractors, Messrs. Budd & Holt, the line finally opened on 17 December 1877 and was worked the Great Western Railway. The Malmesbury Railway was absorbed into GWR on 1 July 1880.
With the completion of the South Wales Direct line from Swindon via Badminton to the Severn Tunnel on 1 July 1903, the Malmesbury Railway became connected passed under the new line at Great Somerford. On 17 July 1933 a new spur between the branch and the South Wales main line was provided at Little Somerford, and the line from there to Dauntsey closed, leaving the Malmesbury Branch a mere three and three quarter miles long.
The line closed to passenger traffic on 10 September 1951, with closure to goods following on 12 November 1962, after which the track was lifted.