High Peak Liberal DemocratsThe vote, by 358 to 256, is the first Parliamentary defeat for the government's Brexit bill.
However, MPs will be able to remove their changes when the bill returns to the House of Commons.
Ministers say the issue is a priority but must be part of a deal protecting UK expats overseas.
Live: Peers debate Brexit bill
Reality Check: How many EU nationals in the UK?
UK has 'moral' duty to Gibraltar on Brexit
The bill will give Theresa May the authority to trigger Brexit under Article 50 of the Lisbon Treaty and begin official negotiations.
The amendment backed by the Lords requires the government to introduce proposals within three months of Article 50 to ensure EU citizens in the UK have the same residence rights after Brexit.
But it could be overturned when MPs, who have already backed the Brexit bill without amendments, vote on it again.
The government is expected to attempt to overturn the defeat when the legislation returns to the Commons.
The Department for Exiting the EU said: "We are disappointed the Lords have chosen to amend a bill that the Commons passed without amendment.
"The bill has a straightforward purpose - to enact the referendum result and allow the government to get on with the negotiations."
The government said its position had "repeatedly been made clear", saying it wanted to guarantee the rights of EU citizens and British nationals "as early as we can".
Ahead of the vote, the government made a last-minute attempt to persuade peers not to change the draft legislation.
Brexit Minister Lord Bridges said the government had been keen to reach an agreement with other EU nations on the issue.
However, he said, "a small number of our European counterparts" insisted there could be no discussions until the formal Brexit talks begin once Article 50 had been invoked.
But most peers wanted a unilateral move from the UK government.
Labour's shadow Brexit minister Lady Hayter said the concerns of EU nationals here and British expats living in Europe shouldn't be "traded against each other".
She added: "These people need to know now - not in two years' time or even 12 months' time. They simply can't put their lives on hold."
Seven Conservative peers voted in favour of the amendment, which was proposed by Labour with the support of the Liberal Democrats.
Among those opposing it during the sometimes heated exchanges was former Conservative cabinet minister Lord Tebbit, who said the debate seemed to focus on "nothing but the rights of foreigners".
Printed (hosted) by Prater Raines Ltd, 98 Sandgate High Street, Folkestone CT20 3BY
Published and promoted by Barrie Taylor on behalf of High Peak Liberal Democrats all at Daleside, Linglongs Road,, Whaley Bridge SK23 7DS and by Richard Salmon, Derbyshire Liberal Democrats on behalf of Stan Heptinstall (Liberal Democrats) both at 9 Walnut Road, Belper DE56 1RG.
The views expressed are those of the publisher, not of the service provider.
Website designed and developed by Prater Raines Ltd, with modifications by High Peak Liberal Democrats