SEATTLE — For a baseball team from the heartland, the West Coast is supposed to mean long flights and late nights, the body tested in a faraway time zone. For the Kansas City Royals in 2017, this coast has transformed a season.

On a Wednesday night at Safeco Field, Salvador Perez clubbed a two-run homer in the top of the 10th inning, the decisive blow in a 9-6 victory over the Seattle Mariners. The Royals completed a three-game sweep and moved to 10-2 across two West Coast road trips.

The first trip, which commenced in early June, sparked a torrid run up the American League standings. The latest has solidified their place in the postseason chase. With three games remaining before the All-Star break, the Royals (44-40) moved to a season-high four games over .500 and took control of the second Wild Card spot in the American League. They sit just a half game behind the first-place Cleveland Indians in the AL Central.

Third baseman Mike Moustakas homered for a third straight game, recording his 25th blast of the year. Lorenzo Cain added a game-tying two-run shot in the fifth. The Royals overcame an uncharacteristically mediocre performance from starter Jason Vargas.

The game was decided in the 10th when the offense nicked Mariners reliever James Pazos for three runs. Seattle second baseman Robinson Cano booted a routine grounder with nobody out. Two batters later, Perez drove a sinker into the seats in right field. Alex Gordon tacked on another run with a single to right field.

Closer Kelvin Herrera closed out the game in the bottom of the 10th. The bullpen will receive a brief reprieve on Thursday as the club enjoys its final day off of the first half before opening a three-game series against the Dodgers on Friday night in Los Angeles.

The Royals had knotted the game at 6-6 in the fifth inning on a cracking, 427-foot homer from the bat of Cain. Ahead in the count 1-2, Ariel Miranda missed with a slider and a fastball before laying a 93 mph fastball over the middle of the plate. The baseball left Cain’s bat at 107 mph as he leaned back into his trademark pose.

The Royals ambushed Miranda for four runs in the first on two hits, a walk and a two-run homer by Moustakas, who went deep for the sixth time in eight games. They went quietly in the next three innings before Cain’s blast in the fifth.

The Royals entered the day in position for their first three-game sweep at Safeco Field since 2010. Their All-Star starting pitcher was poised to make his final start of the first half. Vargas entered the night leading the American League in wins (12) and ERA (2.22). The Mariners did something that few teams have done all season: solve Vargas’ change-up, one of the best pitches in baseball in 2017.

Seattle left fielder Ben Gamel ripped a 1-1 change-up into right-center for an RBI single in the first. Catcher Mike Zunino clubbed a first-pitch change-up to left in the second. And designated hitter Nelson Cruz barreled a 1-1 change-up out of the ballpark with nobody on in the third.

The Mariners struck for six runs in the first three frames, matching the most allowed by Vargas all season. Jean Segura added another two-run homer on a fastball in the second as Vargas surrendered three homers in one start for the first time since June 27, 2014.

The Royals had built a 4-0 lead in the first inning against Miranda, who entered the game with a 3.82 ERA in 17 starts. Vargas did not possess his sharpest stuff. His off-speed stuff danced up in the strike zone. The Mariners were not fooled. He concluded his final start before the break by allowing six runs and eight hits in five innings. He will head to his first All-Star Game with a 12-3 record and a 2.62 ERA.

The Royals found a way to win anyway.