The House of Lords voted on Wednesday 358 to 256 for an amendment requiring ministers to protect the rights of EU nationals based in the UK following Brexit.
However, the government's defeat in the Lords could prove a symbolic one as MPs can remove the amendment when it comes back to the House of 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."
May has said that any guarantee of the rights of EU nationals must be part of a deal protecting UK expats overseas.
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.
May has set an end of the month deadline to invoke Article 50 of the Lisbon Treaty, which will trigger the two-year deadline for Brexit negotiations.
MPs have already backed the European Union (Notification of Withdrawal) Bill without amendments and can remove the Lords' amendment when they vote on it again later this month.
The government is said to be confident of defeating the changes to the bill in the Commons.
Jeremy Corbyn, the Opposition Labour leader who ordered his MPs to support the bill unamended when it went through the Commons, described the result of the Lords vote as "great news", raising the possibility that he might tell his MPs to back the amendment in the Lower House.
"The Government must now do the decent thing and guarantee the rights of EU citizens living in the UK," he said.
The Lords will vote next week on a further amendment which would give MPs”meaningful vote” on the outcome of May’s negotiations with the 28-member bloc. If that vote also goes against her, she could come under pressure from her own MPs to agree to that amendment passing into law.
The amended bill will return to the House of Commons on March 13 and 14, when MPs will debate whether to keep the changes.