Tim Cahill became his country's all-time leading goalscorer with two goals to help Australia to a 3-0 lead after 32 minutes but Ecuador struck four times in the second half to boost their World Cup hopes.
The South American side made five half-time substitutions and pulled two quick goals back as Australia's substitute goalkeeper Mitchell Langerak was sent off.
Fidel Martinez swept home in the 57th minute and three minutes later Enner Valencia was knocked down heavily by Langerak who mistimed his rush from goal and paid the ultimate price.
Midfielder Segundo Castillo took the resulting spot-kick and made it 3-2 just after the hour before Ecuador equalised in the 77th minute through Valencia.
Ecuador grabbed the win in stoppage-time when Manchester United's Antonio Valencia broke away on the right and crossed for substitute Mendez to score.
Cahill's milestone moment came on his 67th appearance for his country in the eighth minute, moving him to 30 international goals and past the record of Damian Mori.
Australia grabbed their second when captain Mile Jedinak slotted in a penalty in the 16th minute after Cahill was bundled over in the penalty area.
Cahill, 34, claimed his second when he got down low to meet Tommy Oar's cross and power a diving header past the keeper but Australia's World Cup hopes were jolted by Ecuador's dramatic fightback after the break.
- Sports & Recreation
- Tim Cahill
- Mitchell Langerak
- Enner Valencia