The lords are hearing a final appeal over whether Britain had the right to impose special emergency measures, now used to hold 12 foreigners indefinitely and without charge.
To enact the law, Britain declared a state of emergency and suspended parts of the European Convention on Human Rights.
"Did the attack in the United States, in New York threaten the life of the nation? Plainly, it did," Attorney-General Lord Goldsmith told a panel of nine senior members of parliament's
House of Lords sitting as the country's highest court.
"There indeed seems to be no limit to the number of people they were prepared to kill. They seek to maximise death and destruction," Goldsmith said on Wednesday.
Lower courts upheld the powers, but until now the law lords have yet to address the measures, as the Supreme Court of the United States did earlier this year over the detentions of "enemy combatants".
"On the morning after September 11, I would be expecting the Home Secretary and authorities to be asking: 'Who in the United Kingdom poses a threat?' I would not expect them to be asking: 'Which foreigner poses a threat?'"
Reaction from one lord
Goldsmith opened the government's case by arguing that attacks on the US in 2001 clearly justified declaring a state of emergency, which the European Convention says can allow the suspension of fundamental rights.
The government concluded that Britain was a target, foreigners were part of the plot, and emergency measures were needed to cope with the threat, he said.
Lawyers for the detainees, backed by human rights groups, argue the measures violate basic rights by allowing the state to lock people up based on secret evidence.
They also say policies that apply only to foreigners are inherently unfair. If they are truly necessary, they should be replaced with policies that apply to all.
In sometimes sharp exchanges, the lords asked Goldsmith to justify measures that apply to foreigners only.
Britain has blasted US policies on
detainees at Guantanamo Bay
"On the morning after September 11, I would be expecting the home secretary and authorities to be asking: 'Who in the United Kingdom poses a threat?'" one of the Lords said.
"I wouldn't expect them to be asking: 'Which foreigner poses a threat?' I would expect them to be asking 'Who?'. Is that the wrong approach?"
Goldsmith said the special powers fall under immigration law, which by its nature treats citizens differently from foreigners.
The powers apply only to those who do not have a right to remain in Britain, but cannot be expelled because their home countries might torture or kill them, he said.
"The choice is to leave them to roam about the streets or to take some other measures to constrain them until they can be deported," he said.
The men are free to leave Britain if they can find another country that will take them, he said, adding that this was a clear difference between Britain's approach and that of the US in Guantanamo Bay, Cuba, which Britain has criticised.
"If this legislation applied in Guantanamo there would not be a single British national there, because they would all have left," he said.
Of 17 men held, one was freed after the government concluded he was no longer a threat and one after a secret tribunal ruled evidence was insufficient.
Another was moved to house arrest after the tribunal ruled his detention had driven him insane.
Two took the option to leave the country.