Spanish police have found an explosive device on a high-speed railway between Madrid and Seville, Interior Minister Angel Acebes has said.
Every kilometre of the track will be checked before the line is reopened
All traffic on the line was halted after the discovery at Mocejon, in the Toledo area, he told reporters.
The minister later said the explosive used was similar to that contained in the 11 March bombs on Madrid trains which killed 191 people.
He said the line would reopen after it was checked "kilometre by kilometre".
Mr Acebes said a new security system would soon be launched to watch over Spain's entire rail network, including armoured vehicles and helicopters manned by police, soldiers and civil guards.
The latest alert comes as Spanish police continue to pursue suspected Islamic militants for last month's train bombings.
The BBC's Katya Adler in Madrid says Spaniards have reacted in stunned disbelief at the news of another attempted bomb attack on the railway.
The train bombs in March killed 191 people
She says the bloody images of the multiple Madrid bombings three weeks ago are still fresh in people's minds.
Trains and motorways are packed across the country at this time of year as millions of families set off on their Easter holidays, our correspondent says.
Bomb disposal experts found between 10 and 12kg (22-24lb) of an explosive resembling dynamite under the line about 60km (40 miles) south of Madrid, Mr Acebes said.
The explosives were connected to a detonator with a 130m cable.
Mr Acebes said the explosive was "the same colour and texture" as that used in the 11 March attacks on four Spanish commuter trains and could be the same material.
He added that it had been taken to the capital for analysis.
Mr Acebes said the bomb failed to explode because it had no trigger. That suggested those responsible may have been scared off by security guards as they were planting the bomb, he said.
He asked people not to jump to conclusions as to who might be behind the foiled attack and appealed to the Spanish public to remain calm and show confidence in the authorities.
Last month's bomb attacks in Madrid have continued to have international repercussions.
In Brussels, Nato foreign ministers on Friday agreed a series of measures to fight terrorism, including more sharing of intelligence.
The decision came on the day the military alliance officially welcomed seven new members.
And in Washington, security officials warned that the Madrid bombings had increased the level of concern about a possible attack on US soil.
The FBI and the department of homeland security said extremist groups might try to bomb buses and rail lines in the US, hiding explosives in luggage and carry-on bags.