After the Las Vegas shooting, the White House said it was “premature” to discuss gun laws. But after the New York attack, President Trump said immigration laws must change. (Bastien Inzaurralde/TWP)

President Trump moved quickly Wednesday to gain ­political advantage in the wake of the New York terrorist attack, casting blame on Democrats for lax immigration laws and calling the criminal justice system’s handling of suspects “a joke.”

A day after a man, identified by authorities as an Uzbek immigrant, killed eight people on a Manhattan bike path in an act authorities said was inspired by the Islamic State, Trump seized on the deadly crime to renew his calls for a series of hard-line policies.

The president said he would move to eliminate a popular “diversity lottery” for foreigners seeking U.S. visas and direct the State Department to ramp up “extreme vetting” of immigrants. He also suggested he would consider sending the suspect, Sayfullo Saipov, a legal permanent resident of the United States, to the U.S. military prison in Guantanamo Bay, Cuba.

“We have to get much tougher,” Trump said.

“We have to get much smarter. And we have to get much less politically correct. We’re so politically correct that we’re afraid to do anything.”

Trump campaigned on vows to get tougher on terrorism and immigration, but his agenda has been largely stalled in Congress and in the federal courts, where judges have blocked several attempts by the administration to enact a sweeping travel ban on immigrants from a handful of countries, although Uzbekistan is not one of them.

It was not clear how much action Trump could take on his own to make good on his renewed pledges.

But his response — including blaming Senate Minority Leader Charles E. Schumer (D-N.Y.) for helping create the visa program that allowed Saipov to enter the country — stood in sharp contrast to the White House’s reaction to the mass shooting in Las Vegas last month that killed 59 people at a country music concert.

After that attack by a Nevada man who killed himself, Trump denounced the shooter’s act as “pure evil,” but White House aides and Republican allies rejected calls by Democrats for a renewed debate over gun-control laws, saying it was not appropriate to politicize the tragedy.

On Wednesday, however, Trump said the United States needs a system of “punishment that’s far quicker and far greater than the punishment these animals are getting right now. They’ll go through court for years. . . . We need quick justice, and we need strong justice.”

Trump also said the criminal justice system is “a laughingstock” in how suspects are prosecuted and added that keeping the country safe will require “unflinching devotion to our law enforcement, homeland security and intelligence professionals.”

The comments are remarkable given the Justice Department’s heavy focus on prosecuting terrorism cases.

Twenty-nine-year-old Sayfullo Saipov is the suspect held in the terrorist attack that left eight people dead in Lower Manhattan on Oct. 31. Here’s what you should know. (Amber Ferguson/The Washington Post)

Just two weeks ago, a federal jury convicted a New Jersey man born in Afghanistan for detonating explosives in the Chelsea neighborhood of New York last year.

Referring to Saipov as an “animal,” Trump asserted that the 29-year-old was responsible for the entry of 23 immigrants, many of them family members. The president said such “chain migration” endangers national security, and he called for the elimination of the State Department’s “diversity visa lottery,” through which authorities have said Saipov came to the United States in 2010.

It was not clear what evidence the president had for the claim; legal permanent residents are permitted to sponsor only their spouse and their children under 21 years of age for green cards, according to U.S. Citizenship and Immigration Services.

The lottery program issues up to 50,000 visas per year to people from dozens of countries, granting them legal permanent residency. The aim is to mix up the nation’s melting pot, although the visas are a tiny fraction of the roughly 1 million green cards issued annually.

“It’s not good. It hasn’t been good. We’ve been against it,” Trump said.

He has expressed support for an immigration bill from Republican Sens. Tom Cotton (Ark.) and David Perdue (Ga.) that would slash legal immigration levels by half over a decade, including eliminating the diversity lottery. Democrats and many Republicans have opposed the bill.

“This man that came in, or whatever you want to call him, brought in with him other people, and he was the primary point of contact for — and this is preliminarily — 23 people that came in or potentially came in with him,” Trump said. “That’s not acceptable.”

Asked whether Saipov’s family members represent a security threat, Trump replied: “They certainly could. He did. They certainly could represent a threat.”

In 1990, Schumer, then a House member, introduced the bill that helped create the diversity visa program, which passed Congress with a bipartisan majority and was signed into law by President George H.W. Bush, a Republican.

In 2013, however, Schumer was part of a bipartisan group of senators that sought to end the program as part of a comprehensive immigration reform package that later died in the Republican-controlled House.

Schumer denounced Trump’s remarks and pointed to President George W. Bush’s response to the Sept. 11, 2001, terrorist attacks, in which he attempted to rally the nation to find a common approach to confront the threat.

“All President Trump does is take advantage — horrible advantage — of a tragedy and try to politicize and divide,” Schumer said.

“This is a tragedy. It’s less than a day after it occurred, and he can’t refrain from his nasty, divisive habits.”

At the White House, press secretary Sarah Huckabee Sanders rejected the notion that Trump had politicized the attack, saying that the president has consistently spoken about the need for tougher immigration laws.

“This is something that, frankly, the president has been talking about for a long time,” Sanders said.

“This isn’t a new policy. This isn’t a new position. This isn’t a new conversation.”

The clash once again pitted the two New Yorkers against each other over an attack that played out miles from where they grew up.

It also raised questions about whether the fallout could further complicate the already tenuous path for Congress to find a compromise on legislation to legalize hundreds of thousands of younger undocumented immigrants, known as “dreamers.” They were thrust into limbo in September after Trump announced the termination of a deferred deportation program, created by President Barack Obama, that allowed them to live and work in the United States.

“I have always believed in immigration as good for America — so do the vast majority of Americans. I stand by that today,” Schumer said.

“It’s a good thing for America. Whether President Trump believes that or not, we don’t know, because some days he’s very anti-immigrant and then he calls [House Minority] Leader [Nancy] Pelosi and I to the White House and says, ‘Let’s help the dreamers.’ ”

Other New York Democrats also took umbrage at Trump’s response to the attacks.

Gov. Andrew M. Cuomo said the president’s tweets against Schumer and the immigration system were intended to “point fingers and politicize the situation.”

Such tactics “play into the hands of the terrorists to the extent you disrupt and divide and frighten people in this society,” Cuomo said.

Sanders said Trump spoke on the phone with Cuomo and New York Mayor Bill de Blasio (D).

A summary of the call from de Blasio’s office said the president praised the efforts of the first responders and offered federal assistance in the investigation, while the mayor thanked Trump for the help from homeland security officials.

The two did not have much else to talk about, however. The call, the mayor’s office said, lasted approximately five minutes.

Philip Rucker and Sean Sullivan contributed to this report.