More than one million of them were expelled to Mexico or their native countries, according to data from US Customs and Border Protection.
Agents apprehended people from more than 160 countries.
President Joe Biden’s popularity in opinion polls has been sinking, partly as a result of his immigration policy.
Just 35% of Americans said they approved of his handling of the issue, in an Associated Press-NORC Center for Public Affairs Research survey earlier this month.
Mr Biden promised a more humane immigration policy than his predecessor Donald Trump, but the US-Mexico border has been engulfed in crisis for much of the Democrat’s nine-month-old presidency.
The detention numbers for the 2021 fiscal year, which ended in September, are the highest since 2000. That year, more than 1.6 million migrants were held at the US-Mexico border. But the number has not reached 1.7 million since US authorities first began tracking such entries in the 1960s.
“The large number of expulsions during the pandemic has contributed to a larger-than-usual number of migrants making multiple border crossing attempts,” the US Customs and Border Protection said.
Those trying to enter the US illegally were mainly from Mexico, Guatemala, Honduras and El Salvador.
Of all those detained, the biggest category were adults travelling without children – more than 1.1 million (or 64%).
At the same time, the US authorities said they encountered more than 145,000 unaccompanied children – a record number.
Almost 11,000 of those children remained in government custody on Friday.
A BBC investigation of the Fort Bliss detention centre in Texas earlier this year found reports of sexual abuse, Covid and lice outbreaks, hungry children being served undercooked meat and sandstorms engulfing the desert tent camps where the young people were being held.
Republicans have blamed Mr Biden’s promise to create a pathway to citizenship for immigrants for fuelling the surge.
Mr Biden – who is making one of his regular trips to his home in Delaware this weekend – has been facing questions this week about why he has not visited the border. The White House press secretary told reporters on Friday that Mr Biden drove by the border in 2008 when he was campaigning to be Barack Obama’s vice-president.
Edited By Salome Campanioni