Ravens strong safety James Ihedigbo tips the ball into the air sending it into the hands of Bengals wide receiver A.J. Green for a touchdown to end regulation. (Nick Wass/AP)

A game the Baltimore Ravens thought they had won about 30 minutes earlier was finally won thanks to the right leg of Justin Tucker.

After the Cincinnati Bengals forced overtime Sunday with a 51-yard Hail Mary touchdown pass from quarterback Andy Dalton to wide receiver A.J. Green with no time on the clock in regulation, Tucker connected on a 46-yard field goal in overtime, giving the Ravens a much-needed 20-17 victory in front of an announced 70,922 at M&T Bank Stadium.

The victory — the Ravens’ first since Oct. 6 — ended a three-game losing streak and pulled the Ravens (4-5) within a game and a half of the first-place Bengals (6-4) in the AFC North.

“I don’t know if this was exciting. It would’ve been more exciting if you were on Cincinnati’s side,” said quarterback Joe Flacco, who threw two first-half touchdown passes but also turned the ball over three times. “I don’t know if it was more exciting as it was one of those ones where you go afterward, ‘Phew.’ I’m glad we won this one.”

The Ravens’ defense forced three interceptions by Dalton and sacked him five times.

However, all of that was overshadowed by the final seconds of regulation, when the Bengals completed a comeback from down 17 points to tie the game.

Trailing 17-10, the Bengals got the ball back on their 40-yard line with 1 minute 28 seconds to play and no timeouts. When Elvis Dumervil had sacked Dalton for the third time, Cincinnati had to spike the ball to set up one final throw toward the end zone. The Hail Mary was deflected by the first wave of defenders just shy of the end zone, and then it hit off James Ihedigbo’s hands. Green caught the deflection toward the back of the end zone with no defender close to him.

The Bengals won the coin toss and had the first possession of overtime. But on fourth and two from the Baltimore 33, Dalton threw a dump-off to rookie Giovani Bernard, who was pulled down by Corey Graham and Ihedigbo for a loss of 11 yards.

The Ravens took over at their 44 and then were in Tucker’s range when Flacco hit tight Ed Dickson for an eight-yard first down.

Team victory in so many ways,” Ravens Coach John Harbaugh said. “I think what it was all about in the end, and the thing I’m proud of as a coach, is the heart of our guys. I feel like they showed the heart of champions today. Where this leads us we will find out.”

The Ravens led 17-0 at halftime and 17-3 heading into the fourth quarter. However, they got nothing going offensively in the second half, and when Dalton hit Bernard for an 18-yard touchdown, the Bengals trailed just 17-10 with 8:22 to play in the fourth quarter.

The Ravens finally got a couple of first downs as Flacco hit Jacoby Jones for eight yards and Dickson for 18. A personal foul by Bengals linebacker Vontaze Burfict, who hit Flacco as he was going out of bounds, allowed the Ravens to move into Cincinnati territory.

However, Flacco was hit by Carlos Dunlap, and the Bengals recovered the fumble, taking over the ball at midfield. The Ravens held, but they were unable to run out the clock, and Cincinnati needed just the one final play to tie the game.

The Ravens entered the game having not had a lead since their Week 5 victory over the Miami Dolphins. They hadn’t scored a first-quarter touchdown since Week 1, and they had watched their opponent score first in six of eight games this season.

That’s why it was no surprise when Harbaugh said this week that in his talks to the team, he had stressed importance of starting fast.

The Ravens responded, scoring on their second drive to take a 7-0 lead. The score, a one-yard touchdown pass from Flacco to tight end Dallas Clark on third and goal, was set up by a 48-yard pass interference penalty on the Bengals’ Reggie Nelson. The Ravens called for a flea flicker on the play, and Jones was wide open, but Flacco underthrew him. While working his way back to the ball, Jones was interfered by Nelson.

Flacco’s second touchdown of the day, a seven-yard strike to Torrey Smith — who held on despite a hard hit by Nelson — was the result of the Ravens getting the ball at the Cincinnati 11 following Ihedigbo’s interception of Dalton.

The interception was part of a dominant first-half effort from the defense. The Ravens held the Bengals to 102 total yards while shutting them out over the first 30 minutes. Dalton was just 8 for 21 with an interception.

Adding to the Bengals’ woes, they were called for seven first-half penalties for 114 total yards. If not for a sluggish first half offensively — the home team gained just 94 yards and was 1 for 7 on third down — the Ravens could have put the game away.