A railway that would lead to the Haapsalu resort was first planned at the beginning of the 1870s. The Baltic Railway Association opened the first railroads in Estonia in 1870 and considered establishing a Kolga-Haapsalu or Keila-Haapsalu line alongside the Tapa-Tartu railway. This plan, unfortunately, was dropped due to the lack of resources, but the idea and expectation of establishing a railway remained.
After the Baltic Railway was nationalised, conditions were more favourable for the Haapsalu town authorities to proceed with the railway, and they succeeded. On 17 May (or 19 May in some sources; 30 May / 1 June by the new calendar) 1902, Emperor Nicholas II satisfied the request of Earl Evald von Ungern-Sternberg (mayor of Haapsalu in 1898–1902) and issued an order for building the wide-gauge (1,524 mm) Keila-Haapsalu railway. The railway was established concurrently in three divisions and it was led by experienced engineer Peter (Pierre) Friedrich von Götte; preparations began already in the same year. Rails were laid down in Haapsalu in the summer of 1904 and on 10 August (23 August by the new calendar) 1904, the first train arrived with a festive welcome from Keila to Haapsalu, near the Lihula main road. Provisional railway traffic began on 15 December (28 December by the new calendar) of the same year, with stations in Riisipere (Ризенберг), Risti, Palivere (Паллифер), and Haapsalu (Гапсаль). Since 15 January (28 January by the new calendar) 1905, mail cars began transporting mail, whereas the old Tallinn-Haapsalu mail tract was closed. Direct trains began to move between Haapsalu and Tallinn on 10 August (23 August by the new calendar) 1905, and in autumn, the Keila-Haapsalu railway of 73 versts (78 km), which had cost over 3.6 million roubles, was handed over to the state. The first imperial private train arrived to Haapsalu on 24 June (11 June by the old calendar) 1908, with Grand Duchess Elizaveta Feodorovna and Dmitri Pavlovich, cousin of Nicholas II, who vacationed here. The first direct trains between Saint Petersburg and Haapsalu were reportedly established in the summer of 1909. During World War I, three stations were opened on the Keila-Haapsalu railway, which had originally been abandoned: Taebla, Ellamaa, and Vasalemma (1915). In 1915, during the construction of Peter the Great’s naval fortress, a military railway was also established, leading to Rohuküla to the new military harbour. The siding was rearranged and taken into use in 15 June 1921 as a public station for transporting passengers, luggage, and goods. At the beginning of the 1920s, new stops were established in Sooniste (station as of 1924, ‘Turba’ as of 1934) and Laitse (1923). The first multiple unit trains with petrol engines began to travel alongside steam locomotives on the Haapsalu railway on 1 November 1928 and eight new stations were opened on the Tallinn-Haapsalu line: Valingu, Kulna, Ingu (‘Jaanika’ as of 1937 by the Jaanika mail farm), Metsa, Vaharu (‘Jaakna’ as of 1937 by the Jaakna mail farm), Nigula, Ridala, and Uuemõisa. A multiple unit train with a more powerful diesel carriage began operating the Tallinn-Haapsalu line on 26 July 1935, and due to its fast speed (1 h 59 min), people started calling it ‘the Flying Westman’. World War II and the German occupation changed the gauge of the Keila-Haapsalu railway to conform with the European standard – 1,435 mm. The rail was re-nailed in the fall of 1941 and it became wide-gauge again only in the spring of 1945. It took six months in 1965 and 230,000 roubles to extend the electric railway from the Keila station to Vasalemma, and the first electric trains travelled on that 12-kilometre segment on 15 July 1965. The following summer, first four-carriage diesel trains began operating on the Tallinn-Haapsalu line; people called them cabbageworms. In the spring of 1981, the electric railway was extended from Vasalemma to Riisipere and the segment, which had cost nearly one million roubles, was opened on 4 September 1981. Thus, the oldest part of the Keila-Haapsalu railway became an electric railway while the rest of the rail degraded. On 22 September 1995, after the restoration of Estonian independence, Eesti Raudtee made a decision to stop transporting passengers because of low speed and high expenses. Freight transport continued, but at the same time, the segment was prepared for privatisation. In November 1996, the Ministry of Transport and Communications proposed to the Estonian Privatisation Agency to sell the Riisipere-Haapsalu railway. In the summer of 1997, it was the first public railway line entered into the privatisation list. In December 1997, the Riisipere-Haapsalu railway became the siding of the Riisipere station; its right of ownership was transferred on 11 March 1998 to Uuemõisa Taavi, a small Läänemaa business, after concluding a purchase and sale contract on 12 December 1997, paying a symbolic fee of 5,200 kroons, and submitting the mandatory investment warranty. Maintenance works would be performed by the newly established OÜ Haapsalu Raudtee that began freight transport on the line on 1 May 1998. The century-long railway connection was disrupted in May 2004, when the steel rails were dismantled. A new popular light traffic road was established in the summer of 2008 in the place of the railway dam of Riisipere-Haapsalu-Rohuküla, now clean from rails and sleepers. The state began to restore the Riispere-Turba railway segment in 2019 and Haapsalu is eagerly waiting for the joyful hoot of another train.