Two men were held on high bail Wednesday after a shootout with undercover officers and a subsequent manhunt in Roslindale Tuesday evening, prosecutors said.

Luis Colon, 25, of Lawrence and Eric Rosado-Gonzales, 25, of Dorchester, were both held on $500,000 bail during their arraignment in West Roxbury. 

Authorities said that Colon and Rosada-Gonzales were already out on bail on other charges, prompting the judge to revoke their bail in those cases and placing both men behind bars for 60 days. 

Undercover officers reportedly told the court that the two men sold undercover officers heroin three separate times, eventually offering to sell them two handguns and an uzi submachine gun Tuesday near 37 Newburg St. 

Instead, both officers were ambushed by the men, prosecutors said, with one officer fighting his way out from having a gun pointed at his head. 

At one point, Colon and an officer allegedly exchanged gunfire, but no one was struck. Both men fled, and were later apprehended by police. 

Colon faces charges that include unlawful possession of a firearm, unlawful possession of ammunition, unlawfully carrying a loaded firearm, discharging a firearm within 500’ of a residence, and armed assault with intent to murder. 

Rosado-Gonzalez was charged with assault with a dangerous weapon, armed assault with intent to rob, and assault and battery with a dangerous weapon, prosecutors said. 

“These defendants allegedly set in motion events that could have gotten someone shot or much, much worse,” Suffolk County District Attorney Daniel F. Conley said. “We’re extremely lucky that no one was seriously hurt.” 

Both are due back in court on Oct. 28.