The loss snapped the Rays' seven-game winning streak. Tampa Bay, with the major's best record at 55-33, lost for the second time in the last 13 games. The Rays went 1-for-19 with runners in scoring position.
"Today was a tough day for us," Pena said. "We couldn't capitalize."
Pena nearly salvaged a bad day with his home run off Soria, who blew his second second save in 25 chances.
"You know it's going to happen at some point in time," Royals manager Trey Hillman said. "That fastball caught just a little too much of the plate. It was kind of right in Pena's nitro zone and he got it out of the ballpark."
Billy Butler reached second to start the 10th on a throwing error by Rays third baseman Evan Longoria. Pinch runner Esteban German advanced to third on Mark Teahen's grounder. After Dan Wheeler (2-4) intentionally walked Ross Gload, Buck lined his fourth homer of the season down the left-field line. Two pitches later, Aviles homered to make it 7-3.
"I hit it good and the way it was hooking, it made me a little nervous, but it stayed true just enough," said Buck, who turned 28 on Monday.
"That's what happens when you miss your spots," Wheeler said. "I didn't make my pitches and it cost us the game."
Soria (1-1) also allowed Eric Hinske's solo homer in the bottom of the 10th.
Aviles had three hits and David DeJesus had three hits and two RBIs for the Royals, who avoided being swept in the four-game series.
"It was good to see us battle back," Hillman said.
Carl Crawford started in center for the first time since June 18, 2006, and his lack of hustle helped the Royals take a 3-2 edge when Gload singled up the middle in the third. Crawford failed to charge the ball and Teahen scored from first, never slowing down en route to the plate.
"I think I got a little lackadaisical," Crawford said. "I didn't think he was running. Then I looked up ... and it was too late by then. It was just a bad effort on my part. I probably could have gotten to the ball a little quicker. I was doing my normal thing that I do in left, and forgot I was in center. You've got to be a little more aggressive in center."
Crawford moved over from left to center because center fielder B.J. Upton was given the day off. Crawford made a nice catch going back toward the warning track on Billy Butler's drive in the fifth.
The Rays finish the first half of the season with two games at the Yankees and four in Cleveland against the Indians.
Crawford became the ninth player since 1900 to reach 300 steals before the age of 27 when he swiped second base in the first. Crawford, who turns 27 on August 5, joined Rickey Henderson, Ty Cobb, Tim Raines, Vince Coleman, Cesar Cedeno, Clyde Milan, Eddie Collins and Sherry Magee in accomplishing the feat. ... Hillman talked with members of the U.S. Military All-Star baseball team and let the players shag and take grounders with the Royals during batting practice. Several Royals players traded uniform tops with the All-Stars during the workout. ... Rays reliever Al Reyes (right shoulder) could be reinstated from the 15-day disabled list right after the All-Star break. ... Longoria has 18 RBIs in his last 14 games. ... DeJesus is 27-for-57 with runners in scoring position.