The train departed Yiwu in eastern China, a major wholesale centre for small consumer goods, on November 18th and passed through Kazakhstan, Russia, Belarus, Poland, Germany, and France during its 21-day trip.
The newly operational route is the longest railway route in the world, longer still than Russia's famous Transsiberian railway linking Moscow to Vladivostok near Russia's border with China.
The journey time was over ten days shorter than if the goods transported by the train had been shipped by sea, Spain's public works ministry said.
The train's 40 shipping containers transported goods made in Zhejiang province, including spinning tops for children and cutting tools. The train will return to China with wine, olive oil and cured ham.
Speaking a ceremony in Madrid, Li Qiang, the governor of China's Zhejiang province where Yiwu is located, said the route was important to "implement the strategy of developing a new 'silk road'".
China has a regular direct freight train service to Germany, Europe's largest economy.
One route links the Chinese megacity of Chongqing to Duisburg, a steel-making town and one of Germany's most important transportation and commercial hubs. The other route links Beijing, the Chinese capital, to Hamburg, Germany's second-largest city.
The plan is to create a similar regular route between China and Spain, Spanish Public Works Minister Ana Pastor told reporters after the train arrived at a logistical centre near Madrid's main railway station.
The Spanish capital already is "a European and international distribution hub" with good links to both Africa and Latin America, she said.
Euro Cargo Rail, a subsidiary of German freight operator DB Shenker Rail, is studying the possibility of starting a regular service between China and Spain during the first half of next year with two monthly trips.
Roughly 80 percent of global trade is shipped by boat as freight train service faces several technical and bureaucratic hurdles which vary according to country. The goods on the train which arrived in Madrid for example had to be transferred to different wagons at three points during the trip because of incompatible track gauges in different countries.
But rail transport is less expensive, more environmentally friendly and faster than maritime shipping, according to DB Shenker Rail.
China is the European Union's biggest source of imports, according to the European Commission.