Alex Cobb dodged trouble for nearly seven innings and the Rays pitched their way to another must-have win on the road, beating the Cleveland Indians 4-0 Wednesday night in the AL wild-card game.

Cobb, who missed a chunk of the regular season after he was hit in the head by a line drive, quieted a thundering Cleveland crowd and ended the Indians’ unexpected season.

Delmon Young homered in the third inning off rookie Danny Salazar as the Rays, playing in their third city over four days, advanced to face the AL East champion Red Sox in the division series starting Friday.

Cobb’s comeback in August from his frightening injury helped stabilize the Rays, who have spent the past two weeks winning crucial games to make the postseason for the fourth time in six years.

Cobb pitched out of massive jams in the fourth and fifth, and allowed two runners to reach in the seventh before turning it over to Tampa Bay’s dependable bullpen.

Fernando Rodney worked a perfect ninth, striking out Lonnie Chisenhall to end it. Rodney dropped to one knee and pointed skyward and soon was mobbed by all the Rays, who may be a little homesick but are Boston-bound.

Unfazed by a raucous, red-clad, towel-waving crowd of 43,579 that roared like a jet engine inside Progressive Field, the Rays handled the Indians and will now face their division nemesis, the Red Sox, who went 12-7 against Tampa Bay this season.

David Price set the tone for the Rays’ postseason run by throwing a complete game to beat Texas in the wild-card tiebreaker, and Cobb picked up where his teammate left off. After he was pulled in the seventh, Cobb walked to the dugout where he was first greeted with a high-five from Price.

There was a time when Cobb wasn’t even sure he would pitch again this season.

On June 15, he suffered a concussion when he was struck in the right ear by a line drive hit by Kansas City’s Eric Hosmer. Cobb was sidelined for 50 games and Tuesday he recalled lying on his sofa and wondering if he would be able to help the Rays contend for a playoff spot.

He didn’t want a repeat of 2011, when he couldn’t pitch in the playoffs after undergoing surgery to remove a blood clot in his ribs.

But not only did Cobb go 5-1 after his scary moment, the 25-year-old finished 11-3 in 22 starts and manager Joe Maddon didn’t hesitate giving him the ball for the winner-take-all wild-card game.

The Indians went from 94 losses a year ago to 92 wins under first-year manager Terry Francona and won their last 10 games to make the postseason for the first time since 2007.

But it was one and done for Cleveland, which didn’t capitalize on scoring opportunities. The first three hitters, Michael Bourn, Swisher and Jason Kipnis, went a combined 0 for 12.

The road-tested Rays, who have traveled 3,627 miles since leaving home on Sept. 23, took a 3-0 lead in the fourth on Desmond Jennings’ two-run double.

James Loney and Evan Longoria hit one-out singles before Salazar retired Ben Zobrist on a fly to right, sending Loney to third. Jennings, who recently missed time with a hamstring injury, pulled Salazar’s pitch past diving a diving Chisenhall at third, and by the time left fielder Michael Brantley, who had been shading Jennings toward center, ran it down, Loney and Longoria scored to give Cobb a three-run cushion.

Cobb was in trouble in the bottom of the inning as the Indians loaded the bases on a double, single and walk. But Cobb got Asdrubal Cabrera to hit a grounder to first baseman Loney, who threw to second for a force and shortstop Yunel Escobar fired to Cobb covering first for the double play.

Cobb pumped both fists in celebration, knowing he had escaped danger.

It was nothing new for Cabrera, an All-Star the past two seasons who struggled in 2013 and went 2 for 15 with the bases loaded.

The Indians threatened again in the fifth, putting two on with none out. But Cobb struck out Bourn, got Swisher to ground to first and retired All-Star Kipnis on a soft-as-cotton comebacker to keep it 3-0.

Francona was confident Salazar, who sailed through Cleveland’s farm system with a rocket right arm, could prolong the season.

“We gave him the ball for a reason,” Francona said. “This stage isn’t too big for him.”

And for the most part, Salazar held his own. But a few mistakes cost him and will undoubtedly give him some restless nights until spring training.

Young’s ninth homer in the past three Octobers gave the Rays a 1-0 lead in the third, and their first hit off Salazar.

Drafted first overall by Tampa Bay in 2003, Young returned to the Rays in August with plenty of postseason experience — and success. He was the ALCS MVP with Detroit last season as the Tigers swept the New York Yankees in four games.

Now he’s on the road with the Rays, who want to travel as deep as they can this month.

NOTES: Young is appearing in his fifth straight postseason: two with Minnesota, two with Detroit and this one with Tampa Bay. … Indians reliever Chris Perez, who lost his closer’s job in the final week of the season after two horrid performances, was kept on the 25-man roster for the game. Francona said it “wasn’t a tough decision” and said part of it was out of loyalty to the two-time All-Star. … Rays RHP Jamey Wright was selected to his first postseason roster in his 18th major league season. … Former Indians slugger Jim Thome was in attendance and got a rousing ovation when shown on the scoreboard.