CARACAS, Venezuela—President Nicolás Maduro demanded the loyalty of Venezuelan soldiers a day after the military’s attaché in the U.S. broke with the authoritarian regime and recognized opposition leaderJuan Guaidó as the legitimate head of state.

“Are you coup plotters?” Mr. Maduro bellowed at dozens of uniformed soldiers kneeling before him in a field at Fort Paramacay in the central city of Valencia on Sunday.

In a scene carried on Venezuela’s many state television channels and posted on social media, the soldiers, carrying rifles, responded with an emphatic, “No!” Mr. Maduro answered, “Traitors never, loyalty, always.”

Mr. Maduro has accused Mr. Guaidó of being a puppet of the U.S. and others instigating a coup. Many top opposition leaders have been jailed, including the leader of Mr. Guaidó’s political party, Leopoldo López, or have been forced into exile or barred from holding office.

The government’s efforts to shore up support came after Col. José Luis Silva became the first high-ranking officer to officially abandon the government since Mr. Guaidó, head of the National Assembly, was chosen to take the oath of office in a street rally and challenge Mr. Maduro, 56 years old. Mr. Maduro’s regime is blamed for widespread human-rights abuses and an economic meltdown that has led three million Venezuelans to flee to other countries.