Denmark has tightened its border controls with Germany, hours after Sweden imposed similar measures to deter migrants entering from Denmark.
Danish Prime Minister Lars Loekke Rasmussen said the decision was "not a happy moment" but Denmark "must respond" to Sweden's restrictions.
Danish police will carry out border spot checks for the next 10 days.
The two countries are the latest to impose controls in Europe's Schengen passport-free travel area.
In a letter to the European Commission, Inger Stojberg, Denmark's integration minister, said the controls would focus initially on the border with Germany but may be extended to all of Denmark's borders.
She said the measures taken by Sweden meant Denmark was "faced with a serious risk to public order and internal security because a very large number of illegal immigrants may be stranded in the Copenhagen area".
The new controls would not cause a problem for "ordinary" Danes and Germans, Mr Rasmussen said.
"We are introducing temporary border controls, but in a balanced way," he said. "If the European Union cannot protect the external border you will see more and more countries forced to introduce temporary border controls."
Sweden's decision means all travellers wanting to cross the Oresund bridge from Denmark will be refused entry without the necessary documents.
Rail commuters heading to Sweden will have to change trains at Copenhagen Airport and go through ID checkpoints. The move is expected to cause serious disruption to traffic flows from Denmark.
An estimated 20,000 commuters daily cross the Oresund bridge, which connects the Swedish cities of Malmo and Lund with the Danish capital, Copenhagen.
Direct journeys from Copenhagen's main railway station to Sweden will no longer be available and the changes are expected to add around 30 minutes to the current 40-minute commute.
Danish Transport Minister Hans Christian Schmidt called the checks "extremely annoying".
'Not a deterrent'
Holly Snaith, a British academic who commutes from Malmo to her job at Copenhagen University, told the BBC that the changes had added at least half an hour to her journey.
"We are all on tenterhooks hoping that the Swedish government will resolve things soon," she said.
Nicholas Bean, who commutes from Malmo to his marketing job in Copenhagen, said: "Travellers aren't happy about the Swedish government's action. There has to be a better way to handle the problem."
Sweden is trying to reduce the number of migrants entering the country. Some 160,000 people applied for asylum in Sweden last year, the highest number in Europe except for Germany. Most were from Syria, Iraq and Afghanistan.
Responding to the developments, Martin Schaefer, a spokesman for Germany's foreign ministry told the AFP news agency: "Freedom of movement is an important principle, one of the biggest achievements [in the EU] in recent years. Schengen is very important but it is in danger."
Germany introduced border controls of its own on the Austrian frontier in September, and last week Norway, which is not an EU member but belongs to the Schengen area, said refugees coming from other Schengen countries without visas would be turned back.
A similar set of border closures in eastern Europe in October left thousands of migrants stranded in poor weather conditions.