WASHINGTON — President Trump offered a fiery defense on Monday of his decision to pardon Joe Arpaio, the former Arizona sheriff, as Hurricane Harvey made landfall in Texas last week — and claimed he timed it to attract maximum attention as television viewers were glued to storm coverage.

Mr. Trump, who said his action was no worse than late-term pardons issued under the last two Democratic presidents, also suggested that the Justice Department had political motives during the Obama administration for charging the former Maricopa County sheriff in a case concerning his illegal profiling of Hispanics. Mr. Arpaio was convicted last month of criminal contempt for his tactics in hunting down and jailing immigrants in the country illegally, but he was pardoned before his sentencing.

“I thought he was treated unbelievably unfairly,” Mr. Trump said during a joint news conference with President Sauli Niinisto of Finland in the East Room of the White House. The president and Mr. Arpaio share a hard line on illegal immigration and unapologetic support of the police, and the former sheriff was an ardent backer of Mr. Trump’s campaign last year.

“A lot of people think it was the right thing to do,” Mr. Trump said on Monday of the pardon. “Actually, in the middle of a hurricane, even though it was a Friday evening, I assumed the ratings would be far higher than they were normally.”