CARACAS, Venezuela  Ecuadorean soldiers stormed a police hospital Thursday night in Quito where President Rafael Correa was held by rebellious elements of the police forces, and rescued him amid an exchange of gunfire in an effort to end a tense standoff between Mr. Correa and hundreds of protesting police officers and military personnel.

Speaking shortly after the rescue operation, which involved about 500 soldiers who entered the hospital grounds wearing gas masks, Mr. Correa delivered a fiery speech from the balcony of the presidential palace and blamed “infiltrated elements” of the security forces for the day’s events.

It was unclear if anyone died during the rescue, although Mr. Correa said that at least five people had been wounded.