Two substitutes - Admir Mehmedi (48th minute) and Haris Seferovic (93rd) - cancelled out Enner Valencia's opener in the 22nd minute.
Schedule; News; Photos
It seemed the 2014 World Cup finals would see its first draw but Seferovic slotted in Ricardo Rodriguez's grounded cross 30 seconds from the final whistle to gives the Swiss a win.
Switzerland, ranked sixth in the world, held more possession but their South American counterparts were dangerous on the counter.
The first half was a slow affair with neither teams posing any attacking threat.
An unmarked Valencia opened the scoring heading from five yards via a freekick.
The Swiss hogged the possession for the rest of the half but could not find a breakthrough.
The second half seemed to be going in the same vein as Switzerland held most of the possession.
However, this time the Swiss had more positive attacking play and threatened the Ecuador goal more often.
Switzerland scored just 30 seconds before the final whistle went off
Their hardwork finally paid off when substitute Mehmedi, just two minutes after coming on, found the Swiss equaliser.
Rodriguez's flighted corner found the Freiburg striker, who bulleted the header into the net.
The game opened up after the equaliser with both teams going for the win and it was another Swiss substitute, Seferovic, who gave his team a dramatic win 30 seconds from full time.
France beat Honduras 3-0 in another Group E encounter.