Transport minister Raquel S nchez. AP
Russia's invasion of Ukraine in late February has severely disrupted Ukrainian grain exports, hampering harvests and trapping up to 25 million tonnes of wheat and other grain in Kyiv's Black Sea ports.
The war has sent global food prices soaring and sparked fears of famine.
As part of the Spanish project, a Renfe freight train "consisting of 25 containers, each measuring 40 foot (12 metres)" left Madrid late Tuesday for the Polish town of Chelm near the Ukrainian border, the transport ministry said.
It will travel 2,400 kilometres (1,500 miles) to Chelm where it will collect 600 tonnes of grain and return to Barcelona in early September.
"This is a pilot project... to demonstrate the technical and economic viability of transporting grain via the railway network crossing Europe from Lodz in Poland to Barcelona," the ministry said in a statement.
The containers have been fitted with special liners to allow them to carry grain, the ministry said.
On July 22, Russia and Ukraine signed a UN-backed deal brokered by Turkey to lift Moscow's naval blockade and release millions of tonnes of blocked grain, thereby helping avert a global food crisis.
A total of 12 ships have so far left three different Ukrainian Black Sea ports since then.
With the reopening, the Spanish project will also help "to analyse the capacity of land transport to support maritime routes," the ministry said.