"We got a gift-wrapped present from Toronto, I promise you that," A's starter Chris Bassitt said. "My goodness. How he got [designated for assignment] is shocking to every single person on this team, including coaches. I don't know how we got him. I really don't. He is unreal."
Valencia, who also homered in the fourth, finished the series 6-for-11 with two home runs, five RBIs and the walkoff. He drove in the eventual game-winning run in each of the three games he played in against the Astros.
The walk-off was the fifth of his career, and he's now 17-for-40 (.425) with five doubles lifetime against Houston.
Valencia has provided a much-needed spark for a team that had lost eight of 12 before he arrived, but is now riding a three-game win streak for the first time since June 23-25.
"The team's been great to me," Valencia said, "and I've been fortunate enough to come through with some hits and we've won some games. So it's been fun so far."
Valencia didn't do it alone on Sunday, though. The A's pulled ahead twice late in game, the first effort coming in the eighth with RBIs from Billy Burns and Josh Reddick.
It looked like the A's were on their way to another win after Bassitt's dominant start, but Colby Rasmus yanked a three-run shot to right off closer Edward Mujica, who didn't record an out.
"We go up in the bottom of the eighth and we're riding pretty high, " Phegley said, "then there was the dagger in the ninth inning. We're just going to battle. It's not over."
The bottom of the frame was a combination of hustle, strategic hitting, luck and timing.
Canha brought the hustle by beating out a routine grounder to short to start the inning. Phegley consciously chose to take Gregerson's pitch the other way.
Marcus Semien struck out, Burns was intentionally walked and Coco Crisp flied to left before Reddick came to the plate with two down.
Reddick hit a ball that bounced right off Gregerson, and the Astros had no play so everyone was safe and the score was tied. Then came the man who knew how to finish it off.
"We'd probably have at least a couple more losses in this series if Danny Valencia's not here," A's manager Bob Melvin said.
Trevor Hass is an associate reporter for MLB.com. This story was not subject to the approval of Major League Baseball or its clubs.