BALTIMORE -- For the second time in three games, the Baltimore Orioles had an uplifting victory marred by an injury to a key player.

J.J. Hardy homered twice, doubled and drove in five runs, and the Orioles defeated the Tampa Bay Rays 9-2 Tuesday night to move into a tie for the AL East lead.

But starting pitcher Jason Hammel left in the fourth inning with an injured right knee. The right-hander underwent arthroscopic surgery on that same knee in mid-July and was making his second start since returning from the disabled list.

Hammel will be examined Wednesday by the team surgeon. He said the sensation was exactly identical to what he felt in a July 13 game against Detroit, his last start before going on the DL.

"It's a very sharp pain in the knee in the same spot," Hammel said. "I'm hoping it is just scar tissue. I've been told scar tissue can react like that."

On Saturday, Baltimore lost right fielder Nick Markakis with a broken left thumb while defeating the New York Yankees. Both Hammel and Markakis were on the DL earlier this year.

"We've been down this road many times this year with a lot of different challenges," manager Buck Showalter said. "We've operated a good portion of this season without Ham and without Nicky, so we're kind of experienced at it anyway. It's not the kind of experience you want to have."

Hammel had no problem with the knee on Thursday night against the Yankees, and retired 11 of 13 Tampa Bay batters before exiting.

"Against the Yankees, I felt great," Hammel said. "I felt like I was back on track, and I know I can help this team when I am healthy. So it's very frustrating."

Steve Johnson (3-0) got the win with 1 1/3 innings of hitless relief.

With Markakis out, Hardy picked up the slack. He went 4 for 5 to help Baltimore pull even atop the division with the Yankees, who lost 4-3 at Boston. The Rays are two games behind the co-leaders.

Hardy hit a two-run homer in the third inning, doubled and scored in the fifth, singled in a run in the sixth and added his 21st homer with a runner on in the eighth. It was his ninth career two-homer game, the second this season.

"I got a couple pitches to hit and didn't miss them," Hardy said.

Chris Davis homered and Matt Wieters had three hits and two RBIs for Baltimore.

Ryan Roberts and Elliot Johnson hit solo homers for Tampa Bay. It was the first time since Aug. 4 that the Rays lost by more than two runs; eight of their previous 12 defeats were by one run.

"Anybody can get beat by a lot of runs any night," Roberts said. "It didn't go our way tonight, and that's how it happens sometime in baseball."

Roberts left in the sixth inning with a left forearm strain, the result of a tag he made at second base. X-rays were negative, and he held out hope of playing Wednesday in the next game of the three-game series.

"I'm just glad it isn't broke," Roberts said. "If it's up to me, I'm playing. We're in a tight race and these games mean a lot, so I definitely want to play even if it's going to hurt a little bit."

Tampa Bay left-hander Matt Moore (10-10) threw 94 pitches over four innings before being lifted by manager Joe Maddon. Moore allowed two earned runs on four hits and three walks.

Burke Badenhop entered with a run of eight straight scoreless appearances and promptly gave up a double to Hardy, a single to Adam Jones and two-run double to Wieters that provided Baltimore with a 5-1 lead.

Hardy's sixth-inning RBI single came off Cesar Ramos and Davis hit his 25th homer in the seventh off J.P. Howell.

Johnson connected against Darren O'Day leading off the eighth, and Hardy homered off Dane De La Rosa in the bottom half.

The victory improved Baltimore's record against AL East foes to 33-24 compared to 28-44 last year.

Baltimore broke on top with an unearned run in the first inning. Jones walked and scored when Matt Joyce fumbled Wieters' two-out single to right.

Hammel retired the first eight batters before Roberts connected in the third. It was his fourth homer with Tampa Bay since in coming over in a trade with Arizona on July 24.

In the bottom half, Robert Andino led off with a double and Hardy homered to put the Orioles ahead for good.

Game notes

Baltimore leads the season series 7-6 and took the lead in the all-time series, 127-126. ... The Orioles purchased the contracts of OFs Endy Chavez and L.J. Hoes and designated RHP Kevin Gregg and INF Ryan Adams for assignment. ... This was the first of 15 consecutive games against AL East foes for the Rays, who head to Yankee Stadium after this series. ... The Rays will send Alex Cobb to the mound Wednesday night and the Orioles will start rookie Miguel Gonzalez, who's 0-1 with a 6.52 ERA in two starts against Tampa Bay.