Luckily for him and his Jets, an ugly afternoon still ended with an improbable victory.

Geno Smith threw two touchdown passes, including a go-ahead 69-yarder to Santonio Holmes in the fourth quarter, and the Jets overcame a team-record 20 penalties to hang on and beat the Buffalo Bills 27-20 Sunday.

"I love the fact that our team found a way to win," Ryan said. "We persevered and we won. That's really encouraging to me. That tells you about the fight and spirit of this football team, and that's what I'm most proud of."

Smith, who also ran for a score, outplayed EJ Manuel in a matchup of the first two quarterbacks selected in the NFL draft.

But this one was tough to watch with the barrage of penalties. The Jets (2-1) rolled up 168 yards in penalty yardage, and nearly gave it away against the Bills (1-2).

The Jets became the first team to get called for that many penalties and win since the Browns beat the Bears in 1951 despite 21 penalties.

"I know this team is going to get better," Ryan said. "There's no way we can't. Twenty penalties? That's on my shoulders. No question about it, but I know we can get better."

Capping a drive kept alive by four straight penalties on the Jets, Manuel connected with Scott Chandler for a 33-yard touchdown, then hit Stevie Johnson with a pass for 2-point conversion that tied it at 20 with 10:39 left in the game.

"We had a huge momentum swing there and couldn't capitalize on it," Johnson said. "We made our mistakes, but they made 20 penalties and we didn't win. We have to find a way to get it done with that kind of help."

Smith got the Jets right back onto the scoreboard with his big heave to Holmes, who broke away from Justin Rogers as he caught the ball and zipped into the end zone.

"We knew that we had to score," Smith said.

Ryan lost two challenges in a span of three plays in the third quarter and it ended up hurting the Jets.

Manuel scrambled for 21 yards early in the fourth quarter, but lost the ball when he was hit by Dawan Landry and Jaiquawn Jarrett recovered. But officials ruled Manuel was down — and Ryan had no more challenges, with replays showing Manuel appeared to fumble.

The Jets then had a horrendous sequence of four straight penalties, three on Kyle Wilson, who was benched briefly after the last of the calls.

That kept Buffalo's offense on the field. It appeared Fred Jackson also had a fumble during the drive that the Jets recovered, but penalties also negated that and put the Bills in a position to tie.

"We were able to get the game to 20-20," Bills coach Doug Marrone said, "but then we were not able to make the plays to get us over the hump."

Smith, the second quarterback drafted at No. 39, finished 16-of-29 for 331 yards and also had two interceptions.

Bilal Powell ran for a career-high 149 yards on 27 carries, and Holmes had a career-best 154 yards receiving. Stephen Hill also caught a touchdown pass from Smith.

Manuel, who went No. 16 overall as the first quarterback drafted, was 19-of-42 for 243 yards and the score.

It was a costly defeat for Buffalo, which lost cornerback Leodis McKelvin to a hamstring injury, defensive tackle Marcell Dareus to an ankle injury and defensive end Alex Carrington was carted off late in the game with an apparent left knee injury.

Running back C.J. Spiller also left with a knee injury and finished with just 9 yards rushing.

"How many games are we going to win with two turnovers and 20 penalties? Not many," Ryan said. "We will get it corrected. I will get it corrected."