Substitute Haris Seferovic snatched a dramatic winner with 23 seconds left of added time in the opening game of Group E in Brasilia.
The Real Sociedad striker got on the end of a late counter-attack to convert Ricardo Rodriguez's low cross at the near post and make it 2-1.
Ironically the chance came from Ecuador's final attack of the game when Michael Arroyo delayed his shot and was dispossessed by Valon Behrami who launched a swift break.
Poor defending had resulted in the first two goals with Enner Valencia, who scored against England in their World Cup warm-up in Miami earlier this month, heading Ecuador in front in the first half.
Admir Mehmedi nodded home a corner just two minutes after his half-time introduction but fellow substitute Seferovic made an even more important contribution with almost the last kick of the game.
Switzerland will feel justice was done as they had a second-half goal by Josip Drmic - who eventually made way for Seferovic - wrongly ruled out for offside.
The Swiss, ranked sixth in the world, has sailed through qualifying with seven clean sheets in 10 of a relatively easy group but found the tournament proper a different prospect.
They failed to make the knockout stages four years ago in South Africa despite beating Spain in their opening game but this time around Ecuador, ranked 20 places below their opponents, had the better of the first half.
Switzerland hardly helped themselves however as, in the 22nd minute, some slapdash zonal marking for Walter Ayovi's free-kick saw Granit Xhaka and Johann Djourou both get the wrong side of Valencia who easily converted from close range.
The response saw Behrami's close-range header claimed at the second attempt by goalkeeper Alexander Dominguez while Xherdan Shaqiri's shot was blocked by Frickson Erazo with the help of an arm, although a penalty award would have been harsh.
But just 122 seconds after coming on for the second half Mehmedi headed home Ricardo Rodriguez's corner as marker Carlos Gruezo failed to even jump and Dominguez got hopelessly out of position.
Ecuador hit back with Valencia firing just over after a lateral run across the edge of the penalty area and Jefferson Montero's driving run down the left ending with goalkeeper Diego Benaglio deflecting a shot behind with his legs.
With 20 minutes to go Drmic had a goal ruled out despite the touch from Rodriguez's ball coming from Jorge Guagua after Xhaka had dummied.
Benaglio and Djourou's miscommunication and subsequent tangle presented Valencia with an open goal but Steve von Bergen tidied up the loose ball but the goalkeeper redeemed himself to save Arroyo's deflected free-kick despite being wrongfooted.
Arroyo's hesitation in dealing with Manchester United winger Antonio Valencia's cross proved disastrous in the final minute as Behrami blocked and broke down-field to set up the winner.