Houston rallied with two outs in the ninth off Medina with a walk, an infield single by Matt Dominguez and Villar's base hit to right.
That was enough to top Seattle on a night the Mariners managed just two hits. The Mariners are 79-65 with 18 games remaining, a 14-win improvement from this point last season when they were 65-79.
Detroit beat Kansas City to pull into a tie for the AL Central lead, so one of those teams is essentially a half-game ahead of the Mariners in pursuit of the second AL Wild Card spot. Oakland topped the White Sox, 11-2, to regain a two-game lead for the first Wild Card position.
Astros right-hander McHugh held the Mariners to an infield single until first baseman Logan Morrison ripped a one-out home run off the Hit it Here Cafe in right field to tie the game in the eighth inning.
Morrison's shot, his seventh of the season, was estimated at 411 feet and momentarily breathed life into a Mariners club on a quiet night in front of 11,345 fans.
"That was one of the biggest home runs I've ever had in my career," said Morrison, who was acquired from the Marlins last winter. "You could definitely feel the bench be like, 'All right, here we go again. We're going to come back.' It's good we have that feeling. It's a lot better than, 'Well, it's a tie game we're going to give it up again.' I like where we're at. It's a tough loss, but shoot, that's why we play 162."
Rookie southpaw Roenis Elias threw six innings of one-run ball, allowing six hits with two walks and four strikeouts in a strong performance for Seattle.
But Elias took a no-decision after departing with a 1-0 deficit, as he remains 10-12 with a 3.81 ERA. The Mariners have scored two runs or fewer in six of Elias' last nine starts, leaving him 3-4 with a 2.08 ERA since July 21.
"I felt good," Elias said through interpreter Fernando Alcala. "I had a lot of confidence. I was just focused on throwing strikes and getting outs. … Just confidence and keeping calm, that helped me be the Elias I'm used to being."
Rookie first baseman Jon Singleton doubled to drive in a run for Houston in the fourth, an inning that could have been much worse for Elias. After a leadoff single by Chris Carter, shortstop Brad Miller made an excellent stop to rob Jake Marisnick of a base hit, and Singleton then just missed a home run when he laced a line drive off the yellow line atop the right-field fence.
"He made one mistake, a fastball to Singleton," manager Lloyd McClendon said of Elias' outing. "He got that one up. But other than that, he threw the ball pretty good."
The Astros appeared to score again in the sixth when Singleton was initially ruled safe on an infield single as Carter raced home from second. But McClendon challenged the call when replay showed Elias getting his foot down on a toss from Morrison just before Singleton reached the bag, and the call was overturned, keeping the score at 1-0.
Center fielder Austin Jackson had Seattle's lone hit through the first seven frames with an infield single in the fourth on a ball that Villar gloved at shortstop with a diving stop in the hole, but he couldn't throw out the speedy Jackson. Seattle's only other baserunner prior to Morrison's home run was Kendrys Morales, who reached on second baseman Jose Altuve's error in the fifth.
Jackson also made an outstanding running catch deep in the left-center gap to rob Altuve of a likely double in the fifth and tracked down several other balls as well.
"Those defensive plays by Miller and Jackson were really good," Elias said. "They help you keep your confidence up and pitching well."
Counting a Minor League start with Tacoma, Elias has now thrown 165 2/3 innings this season, already exceeding his previous high of 148 1/3 innings with Class A High Desert in 2012. The Mariners will give him an extra two days of rest before his next outing, Tuesday in Anaheim, and he'll have two more starts after that before the end of the regular season.
"We've strategically tried to watch his innings," McClendon said. "We've taken him out of ballgames early. I'm sure he doesn't like it, but we still got to be careful because we're on the edge with him. But he's done a nice job for us."
Elias said he feels fine and is ready to take the ball as much as needed down the stretch.
"I feel good," he said. "I'm just focused on helping the team to go as far as we can, whether it's the playoffs or not. I'm going to be there and helping out as much as I can."