Trump's tweet came hours after a man in Barcelona drove a van at high speeds into a crowd at a popular tourist destination, killing 12 and injuring 50 more, according to local police who are calling the attack an act of terrorism. One man is reportedly in custody in the investigation.
Trump also tweeted message of support for the victims, in which he said the United States "condemns the terror attack."
The message stood in sharp contrast to Trump's reaction Saturday to an attack in Charlottesville, when a man drove a car into a group of people protesting a white nationalist rally, killing a woman and injuring 19 others. An alleged Nazi sympathizer who had attended the rally is charged with second-degree murder in the case.
After than incident, Trump blamed the actions of people "on many sides" of the violent clashes.
Though he denounced the white supremacist hate groups directly two days later, Trump then reversed course and again blamed "both sides" on Tuesday, prompting a widespread political backlash. The president on Tuesday explained that his initial reaction had been muted because he did not have all the "facts" in the case and wanted to be cautious.
In his February recitation of the Pershing story, Trump told a crowd of supporters that the general was having trouble dealing with terrorist attacks and caught 50 suspects.
"He took the 50 terrorists, and he took 50 men and he dipped 50 bullets in pigs' blood - you heard that, right? He took 50 bullets, and he dipped them in pigs' blood," Trump continued. "And he had his men load his rifles, and he lined up the 50 people, and they shot 49 of those people. And the 50th person, he said: You go back to your people, and you tell them what happened. And for 25 years, there wasn't a problem. Okay? Twenty-five years, there wasn't a problem."
At one point in telling this story, Trump said: "By the way, this is something you can read in the history books - not a lot of history books because they don't like teaching this."
Although Trump never used the word "Muslim" in this story, he was clearly referring to Muslim terrorists and at one point commented: "There's a whole thing with swine and animals and pigs, and - you know the story, you know they don't like that." Pigs are deemed impure by the Koran.
There are several versions of the tale circulating, including one in which the prisoners were buried with dead pigs. The pigs' blood on the bullets, according to at least one version, would keep a Muslim from entering heaven.
The Council on American-Islamic Relations denounced Trump's remarks last year in a sharply worded statement that accused the then-candidate of inciting anti-Muslim attacks.