ST. PETERSBURG, Fla. -- Tampa Bay manager Joe Maddon was thinking about what he could have done different as his team entered the bottom of the ninth trailing by four runs. Turned out that a big comeback made it all wasted thoughts.

Sam Fuld hit a game-tying triple and then scored on an errant throw to complete a five-run ninth as the Rays rallied to beat the Kansas City Royals 8-7 on Wednesday night.

"At that point, you start replaying (the game)," Maddon said. "We were just fortunate to get some big hits."

Fuld hit a drive to right center off closer Joakim Soria (5-5) and wound up scoring the winning run when second baseman Johnny Giavotella was charged with an error for a bad relay throw to third.

"It was the craziest 360 feet I've ever run," Fuld said. "I was exhausted."

After Aaron Crow gave up consecutive singles in the ninth, Soria entered and gave up an RBI double to Evan Longoria, a run-scoring grounder by Ben Zobrist and Casey Kotchman's RBI infield single before Fuld's two-out hit. Soria has blown 7 saves in 28 opportunties this season.

"I really don't know what to say," Kansas City manager Ned Yost said.

Salvador Perez got his first career hit, RBI and made several key defensive plays in his major league debut and Melky Cabrera homered and drove in five runs for Kansas City.

The Royals purchased the contract of the highly-regarded catcher from Triple-A Omaha. The 21-year old had a seventh-inning single in three at-bats and added a sacrifice fly. He also picked Kotchman off first during the fourth and Fuld at third in the eighth.

"He really was spectacular," Yost said. "He had a great debut."

Cabrera had a pair of sacrifice flys and extended the lead to 7-3 with a three-run homer with two outs in the ninth off Jake McGee (1-1).

Matt Joyce homered for the Rays. Johnny Damon singled in the ninth to tie George Davis for 65th place on the career hits list with 2,683.

Perez had a stretch starting with two outs in the fifth where he recorded seven straight putouts, coming on two strikeouts and five pop flys.

Royals starter Felipe Paulino allowed one run, three hits and four walks in five innings. He developed back stiffness running earlier this week on the artifical turf and it an impact in his outing.

"It started to tighten up in the third and then it kind of progressively got worse," Yost said. "He'll be fine. I don't anticipate him missing a start."

Kansas City went up 2-0 in the fourth on a run-scoring triple by Giavotella and Perez's sac fly off Wade Davis. The duo are among the 15 different rookies to play for Kansas City this season.

Cabrera made it 3-0 on a fifth-inning sacrifice fly. He had another sac fly in the seventh.

Joyce, batting lead-off for the first time in place of Desmond Jennings, who was rested, cut the deficit to 3-1 with a solo shot in the fifth.

Kotchman pulled Tampa Bay within 3-2 on a sixth-inning RBI single. Joyce fouled out to Perez on a 3-2 pitch with the bases loaded to end the inning.

After Jennings had a one-out pinch-hit RBI single in the eighth, Perez helped preserve the 4-3 lead by picking off Fuld. Greg Holland then struck out Sean Rodriguez.

Davis gave up four runs and six hits over 6 1/3 innings.

Bill Miller joined the umpiring crew, filling in for crew chief Derryl Cousins, who missed his second consecutive game because of a personal medical issue.

Game notes

Rays right-hander Alex Cobb will undergo surgery Friday to remove a blockage in the area of his first right rib. The rookie is expected to be completely recovered by the start of spring training. ... Kansas City rookie LHP Danny Duffy (3-5) will make his 15th big league start on Thursday. "It's a great experience for him up here," Yost said. "He's got a chance to be a good one, but it's still a process, especially with a young pitcher. Just let him continue to pitch." ... Tampa Bay RHP Jeff Niemann (6-4), Thursday's scheduled starter, is 5-0 in eight starts since returning from a lower back strain.