TORONTO — There was bad blood at the beginning. And pure drama at the end as the New York Yankees outdid the Toronto Blue Jays in a battle of ninth-inning rallies Monday.

Trailing 3-1 after seven innings, the Yankees scored one run in the eighth and five in the ninth, then hung on to nip the Jays' attempted comeback at two runs after Toronto loaded the bases with no outs.

The final count? New York won 7-5 to avoid a four-game sweep and leave Toronto with a little dignity after being outscored 16-3 in the first three contests.

There were also three hit batsmen, four ejections and the benches emptied twice. Not to mention 17 hits, three errors, 16 left on base and 13 pitchers used in a three-hour 22-minute baseball smorgasbord.

Even a mini-bat flip, this time not from Jays slugger Jose Bautista but from Yankee veteran Mark Teixeira who started the ninth-inning rally with a homer off Jason Grilli.

And afterwards there was a healthy sample of baseball-speak as the two sides tried to explain the beanball shenanigans in the second inning.

"I don't know, we played a game of baseball, we got into a scuffle. They came back, we made a push," Toronto catcher Russell Martin said pithily.

Martin skipped the part when he looked like he wanted to punch fellow catcher Gary Sanchez's ticket after teammate Justin Smoak became the third hit batsmen and the benches cleared with purpose.

Asked about getting into something with Sanchez, Martin said: "I think everybody was getting into something."

The bad blood started in the first inning when New York starter Luis Severino hit Josh Donaldson on the elbow pad before a sellout crowd of 44,532. Then Toronto starter J.A. Happ took aim at Chase Headley, the first Yankee to go to the plate in the second. It took Happ two pitches to make contact with Headley — he just missed on the first attempt, throwing behind Headley.

Both benches and bullpens emptied but there was no real venom. The umpires cleared the field and the game continued.

Severino, a 22-year-old having a difficult season, raised the stakes by throwing inside at Smoak to open the bottom of the second. He missed inside but hit Smoak on the leg with the second pitch. That prompted a second, more serious pitch invasion that saw a rolling maul of players move across the Rogers Centre infield.

Toronto manager John Gibbons said later that his players were tired of rivals taking liberties.

"Some teams have been taking potshots at us all year long and some guys just got tired of it," he said.

Said Headley: "If they feel like they need to protect their guys, I respect that. But if you do that, you're accepting the consequences."

The Yankees third baseman went further, suggesting the Jays reap what they sow.

"Listen, (the Jays) are the kings of fun. The bat flip, the whole guys yelling at players. (Marcus) Stroman was screaming at our guys when he was pitching, yelling at guys to get off the effing field when he struck somebody out. You've got to take some of your medicine. They certainly have no shortage of emotion and, if you play like that, you've got to expect to get some it back.

Yankees manager Joe Girardi, pitching coach Larry Rothschild and bench coach Rob Thomson were also thrown out.

The physical toll of the evening has yet to be counted. Toronto reliever Joaquin Benoit limped off the field with a calf injury and second baseman Devon Travis was pulled in the sixth. There was no update on either or whether the Travis shoulder injury was linked to the brouhaha.

Severino's first inning was a rocky 32-pitch effort. His second lasted just two pitches.

Said Severino: "I wasn't trying to hit nobody. I wasn't having my control in the first inning. I just tried throwing a good pitch inside and it slipped from my hand."

Said Happ: "They took exception. We did as well ... I wasn't trying to hit Chase but it happened. They can say what they want to say. Eventually cooler heads prevailed but it took a minute there."

Girardi did not seem to mind that Happ threw at his player, given Donaldson was hit. He was more upset that Happ tried twice — and there was no warning from the umpire after the first attempt.

"You throw it behind the guy and you miss, I mean, he's got to be tossed. That's terrible, it's terrible," he said.

Both Martin and Happ expressed surprise that Severino continued to up the ante by hitting Smoak.

As for the baseball, Teixeira admired his one-out solo homer deep to right field off Grilli (7-6), who got the nod with closer Roberto Osuna needing rest, and then flipped the bat gently away.

"We were just having fun," he said with a grin afterwards.

After Didi Gregorius singled, Aaron Hicks went deep to right for a 5-3 lead. Jacoby Ellsbury's RBI single and Sanchez's sacrifice fly off Danny Barnes added to the Jays' pain as the Yankees sent eight men to the plate.

Trailing 7-3, the Jays went to work in their half of the ninth..

With Tommy Layne taking over for Dellin Betances with the bases loaded, Donaldson flied out. Edwin Encarnacion then walked to bring in a run. Pinch-hitter Dioner Navarro's bloop to centre-field made it 7-5. But it was too little too late.

Adam Warren (7-4) got the win and Layne the save, his first.

Recent form may have played a role in the bad blood. The Jays (86-70) are on the rise in the push to the playoffs while the Yankees (80-76) have been sinking fast and had the worst of the first three games of the series.

Lost in the kerfuffle and late-inning collapse was a fine 7 1/3-inning outing by Happ, who was bidding to become just the fourth Blue Jay to win 21 games, joining Roy Halladay (22 in 2008), Roger Clemens (21 in 1997) and Jack Morris (21 in 1992). He was also trying to surpass David Wells (20 in 2000) for most wins by a Toronto left-hander.

Going into Monday's game, the Jays were 23-7 in Happ's starts this season.

Toronto trails idle Boston by six game in the American League East but holds a one-game the top wild-card berth by one-game edge over the Orioles. The Tigers, who lost 7-4 to Cleveland, are two games back of the Orioles.

Baltimore had the day off before starting a three-game series in Toronto on Tuesday.

Monday's contest, which snapped New York's eight-game losing streak in Toronto, marked the close of the Yankees' 12-day, 11-game road trip. They finished their final away swing of the season at 3-8.

Follow @NeilMDavidson on Twitter