Boris Johnson made the comment when replying to a question from Clwyd South MP Simon Baynes in Parliament asking him to praise the efforts of the railway's staff since the coronavirus outbreak.
Mr Johnson, who stood in the constituency in 1997, said he believes the railway has a "fabulous future" with the support of Mr Baynes.
He said: "I have a picture at home of myself and William Hague aboard the Llangollen Steam Railway, I am proud to say, and I congratulate them on what they are doing to raise funds and I have no doubt they have a fabulous future ahead with his support.”
Mr Baynes added: “The PM has very fond memories of the Llangollen Steam Railway from his time as a parliamentary candidate for Clwyd South in 1997. I’m delighted that he has praised the steam railway for all their fundraising work in the current crisis and I know he shares my strong support for all the tourism and hospitality businesses in Clwyd South and across the rest of the country.”
Speaking on the same day the railway's general manager, Liz McGuinness, gave an update on the progress of its appeal.
Last month she had warned the organisation's future was at risk due to a drop off in income.
She said: “Following eight weeks of uncertainty we wanted to give everyone an update on what has been happening here at Llangollen Railway. Firstly, we would like to thank everyone that has donated and purchased shares over the last few weeks. We have now received approximately £75,000 in share purchases and donations, including gift aid, which is amazing!
“We have also applied for the Resilience Grant from the Welsh Government and a Bounce Back Loan from the bank backed by the Government, but have yet to hear regarding either of these applications. Your generosity will help us to keep covering our overheads during this time.
“With listed buildings to maintain and engines needing regular servicing, like all heritage railways we are reliant upon our customers for an income and our income this year will be very much reduced.
“Our donations page will remain open for the foreseeable future and if you are in a position to help us further, we would be very grateful.”