By Krisztina Than and Sandor Peto

BUDAPEST (Reuters) - Long lines of buses left Budapest on Saturday packed with migrants bound for Austria, which said it had agreed with Germany to let them in as Hungary gave in to crowds, including Syrian refugees, that had set out on foot for western Europe.

Hungary's right-wing government said around 100 buses would pick up thousands of migrants camped in front of Budapest’s main railway terminus and another 1,200 striding down the main highway to Vienna led by a one-legged Syrian refugee and chanting “Germany, Germany!”

Austria said they would be granted entry, regardless of European Union rules. Smiling migrants boarded the buses, waving goodbye to Hungarian volunteers and aid workers.

“Because of today’s emergency situation on the Hungarian border, Austria and Germany agree in this case to a continuation of the refugees’ journey into their countries,” Austrian Chancellor Werner Faymann said on his Facebook page.

The Hungarian government cited safety concerns for the decision to lay on buses, after days of canceled trains and confrontation with riot police refusing to let the migrants pass.

But it appeared to mark an admission that the government had lost control in the face of overwhelming numbers of migrants determined to reach western Europe having fled war and poverty in the Middle East, Africa and Asia.

For days, Hungary has canceled all trains going west to Austria and Germany, saying it is obliged under EU rules to register all asylum seekers, who should remain there until their requests are processed.

Many have refused, determined to get to the richer and more generous countries of northern and western Europe, mainly Germany.

Several thousand have been camped outside the Budapest train station, but on Friday a crowd that swelled to over 1,000 broke away, streaming through the capital, over a bridge and out onto the main highway from Budapest to Vienna, escorted by police struggling to keep the road open.

Story continues

Clutching pictures of German Chancellor Angela Merkel, they broke through a police barricade.

Others, in Bicske to the west of Budapest, sprinted down railway tracks, escaping a packed train held back by police for two days, while in the south they broke down barriers and wrestled with helmeted riot officers at an overcrowded border camp near Serbia.

The turmoil contrasted with a pledge by Hungarian Prime Minister Viktor Orban to get to grips with Europe’s worst refugee crisis since the Yugoslav wars of the 1990s; parliament tightened laws that his government said would effectively seal Hungary’s southern border to migrants as of Sept. 15.

Orban hailed “a different era”, but Friday brought more desperate scenes in a crisis that has left Europe groping for unity. A Pakistani man died, police said. State television said he had stumbled and hit his head as he ran down train tracks.

"FREEDOM TRAIN"

Hungary has emerged as the main entry point for migrants reaching the EU by land across the Balkan Peninsula.

Orban, one of Europe's most outspoken critics of mass immigration, took to the airwaves to issue caustic warnings that Europeans could become a minority on their own continent.

But his government's plans for a crackdown appeared to be breaking down in the face of such large numbers headed for Germany, which had said Syrian refugees could register there regardless of where they enter the EU, contrary to EU rules.

More than 140,000 migrants have been recorded entering Hungary so far this year through the EU's external border with Serbia, where Orban's government is building a 3.5-metre (11.5-foot) high wall. Countless others may have entered without registering.

On the border, police gave chase and halted traffic on a nearby motorway after some 300 migrants fled a crowded reception center in Roszke near Serbia.

They were eventually caught, police said, but hundreds broke out again despite a ring of hundreds of officers in full riot gear, clutching shields. Some were taken away by bus.

In Bicske, west of Budapest, a two-day standoff ended after some 300 migrants managed to escape from a train held up by police demanding they disembark and go to a nearby reception center. The remainder went voluntarily.

“No camp. No Hungary. Freedom train,” someone had written with shaving foam on the side of the train.

On Friday, lawmakers adopted some of a raft of measures creating “transit zones” on the border, where asylum seekers would be held until their requests are processed and deported if denied.

The measures introduce jail terms for those who cross the border without permission or damage the fence, and may eventually provide for the use of the army.

"Now we talk about hundreds of thousands but next year we will talk about millions and there is no end to this," Orban told public radio. "All of a sudden we will see that we are in a minority in our own continent."

(Additional reporting by Marton Dunai and Balazs Koranyi in BUDAPEST, Shadia Nasralla in ALPBACH, Austria and Karin Strohecker in VIENNA; Writing by Matt Robinson; Editing by Lisa Shumaker)