When the ancient Greek or Roman playwrights had painted themselves into a corner, plot-wise, they sometimes resorted to the dramatic device known as the deus ex machina, in which one of the gods was hoisted over the stage and dropped in to resolve the otherwise inchoate drama.

Something similar happened this week with Syria. The drama had progressed into a mix of international tragedy and domestic political bathos. President Obama’s threat of military action against Syria was right in principle but garnered no real political support — not least because Obama and his generals agree there is no military solution.

Cue the gods (in Moscow!): The stage directions may have been confusing, starting with a throwaway line from Secretary of State John Kerry, followed up quickly by his Russian counterpart. Suddenly the stage was crowded with a cheering chorus that included U.S., French and Russian presidents, the U.N. secretary general, the Chinese and even Iranians.

Thanks to this welcome plot twist, Obama was able to give a war speech Tuesday night without having to ask Congress to actually commit military power. He could chide his usual tormentors, right and left, that he was upholding values that they supposedly hold dear.

Anyone who thinks this week’s events were simply a theatrical accident should go back to drama school. Obama, Kerry and the Russians have been talking about control of Syrian chemical weapons for many months, most recently a week ago at the G-20 meeting in St. Petersburg, Russia. Let it be said that the mercurial Vladimir Putin (whom Obama regards as the most transactional leader in the world) knows how to propose an 11th-hour deal.

The deus ex machina has been cranked into place, but that doesn’t mean this play is over. The complicated diplomatic part is just beginning. I hope Obama and his allies will keep in mind some basic principles, so that we don’t quickly return to another Syria breakdown:

● Obama can rightly claim that his tough line paid off. The Russians endorsed international control of Syria’s chemical weapons only after Obama threatened to attack and didn’t flinch in St. Petersburg or on Capitol Hill. He may be a weakened president in foreign affairs, but this show of strength regained him some precious credibility.

● The U.N. Security Council now moves to center stage. To avoid a Russian veto, Obama seems ready to accept a resolution weaker than the one France was drafting Tuesday that would have authorized using force if Syria didn’t comply. But Obama should be careful he doesn’t let the language become so squishy that Assad can wriggle away.

● The next step is revival of peace talks in Geneva, where elements of the regime and the opposition can negotiate a cease-fire and transition plan. The United States and Russia, as co-sponsors of these talks, should begin thinking now about how to prevent a chaotic vacuum and sectarian revenge-killing when a political transition begins. The lessons of Iraq and Libya are clear: Reconcilable elements of the Syrian army and state institutions must remain intact so they help the rebuilding.

● President Bashar al-Assad must go. The Russians know this; they’ve repeatedly said so privately to U.S. officials. Now they need to make it happen. U.N. inspectors have gathered evidence that Syrian civilians were killed by sarin nerve gas on Aug. 21; this action could have been done only by the regime. It would be politically dangerous, as well as immoral, to allow Assad to remain in power once these findings are disclosed.

● The United States should step up its training and supply of moderate Syrian rebels — less to topple Assad than to provide a counterweight to jihadists in the opposition and help stabilize a future Syria. The first CIA-trained commandos are now heading into the field, in units of 30 or 40. Step up that flow!

● If Iran wants a seat at the Geneva table, it should prove that it’s ready to become a responsible player in the region. It can’t be part of the Syria solution unless it changes its destabilizing policies — not just in backing Assad but also in its nuclear program, its support for Hezbollah and other actions. A new Iranian president and foreign minister will be in New York in two weeks. The Iranians and the Obama administration should find ways to talk about a new security framework for the region that begins with limits on the Iranian nuclear program.

Ann Telnaes animation: Obama tries to convince Americans to follow him on Syria. (Ann Telnaes/The Washington Post)

● Given the United States’ profound reluctance to fight another war in the Middle East, Israel knows it will have to take responsibility for its own security, including any military action against Iran. The good news is that Israeli power is robust and credible. Both Assad and the Iranians seem to be deterred from reckless action, and the Russians (in secret) are cooperative. Credible threats of force prevent wars.

Read more from David Ignatius’s archive, follow him on Twitter or subscribe to his updates on Facebook.