Two American students have appeared in court in Rome accused of stabbing a plain-clothes police officer to death on a street near their hotel.

Gabriel Christian Natale Hjorth, 18, and Finnegan Lee Elder, 19, from San Francisco, appeared in court in connection with the death of Carabinieri paramilitary police officer Mario Cerciello Rega, 35. The dead man, and a fellow officer, were in plain clothes when they confronted the two Americans in the wake of a drug deal gone wrong, the court heard.

The murder of Rega, said to have recently returned to duty after his honeymoon, was widely condemned. Matteo Salvini, Italy’s deputy prime minister, said he hoped the murderer “never leaves jail”.

Elder is accused of repeatedly stabbing Rega while Hjorth “pummelled” the second officer. The surviving officer was not seriously injured.

The court heard that both students were also being investigated for attempted extortion connected to the alleged drug deal. Investigators say the pair had snatched the bag of a drug dealer in Rome after the man apparently gave them a different substance instead of the cocaine they wanted. It is claimed the students then demanded a cash ransom and cocaine to return the knapsack.

The deceased officer, Mario Cerciello Rega. Photograph: AP

The victim of the bag-snatching contacted Carabinieri after reporting the theft, and the plain-clothes officers were sent to the site, a police statement said. It added that the Americans, “even though the officers identified themselves as being Carabinieri, didn’t hesitate to engage in a struggle, culminating in the mortal wounding” of the policeman. Rega died in hospital soon afterward.

Police said surveillance cameras and witnesses allowed them to quickly identify the Americans and find them in a nearby hotel. Police also said the two Americans were “ready to leave” Italy when they were found. A long knife was also found during a search of their hotel room.

A police statement said that both Americans confronted with “hard evidence” had “confessed to their blame.”