LAWRENCE -- Winning the Governor's Cup is usually a satisfying experience for the Kansas State football team. On Saturday, the main emotion associated with retaining the trophy for another year was relief.

K-State beat Kansas 30-20 at Memorial Stadium in the closest Sunflower Showdown in nearly a decade, needing a pair of late scores and one stop to hold off the underdog Jayhawks.

"It does feel nice to have the Governor's Cup, but (the celebration) was a little more dead this year," K-State running back Alex Barnes said after rushing for a season-high 128 yards and two touchdowns, "because we felt we didn't perform the way we expected to."

It was far from a thing of beauty, as K-State (4-4, 2-3 Big 12) was favored to win by 24, but it will take the result. The victory snapped a three-game losing streak and puts the Wildcats back on track to qualify for a bowl. KU (1-7, 0-5) suffered its seventh-consecutive defeat.

The Jayhawks made things more competitive than expected behind the strong play of quarterback Carter Stanley, who threw for 418 yards and a touchdown while making his first start of the season, but the Wildcats made enough plays to survive and win this rivalry game for the ninth straight year.

K-State coach Bill Snyder is undefeated against Kansas since returning to the sideline in 2009.

The Wildcats pulled ahead after a mediocre first half with one big hit and a few highlight runs in the second half. They won despite starting their backup quarterback, Alex Delton, and finishing things out with their third-stringer, Skylar Thompson.

The game began to swing K-State's way on the first play of the second half. The Jayhawks were riding a wave of momentum after piling up 213 yards in the first half and trailing just 10-6, and they tried to start the third quarter with a big pass. K-State linebacker Jayd Kirby wrecked that plan by hitting Stanley on a blitz. He nailed Stanley with force, jarring the ball loose and then recovering the fumble.

"If we didn't get that we might not have won this game," K-State defensive end Tanner Wood said. "Coming out and getting big plays like that on defense and on special teams is always huge for our team."

Barnes ran in a touchdown three plays later, and K-State led 17-6. Then the Wildcats forced a KU punt and Matthew McCrane connected on his second field goal of the afternoon to make it 20-6.

Stanley added a new element to the Kansas offense that was lacking in recent shutout losses to Iowa State (45-0) and TCU (43-0), and he did enough to throw a real scare into the Wildcats by leading the Jayhawks on a pair of touchdown drives that pulled KU within one score.

It wasn't quite enough, but it did signal some major problems in K-State's secondary.

The Wildcats were torched for the second consecutive week. Oklahoma quarterback Baker Mayfield threw for 440 yards against them.

"I think we are in love with the number 400, somehow that seems to be the number everyone is getting on us," Snyder said. "My takeaway is either we get better at that or we have real problems."

K-State's biggest coverage issues appear to be in one-on-one assignments. The Wildcats are defending spread formations in mostly man coverage, which means linebackers Trent Tanking and Kirby have to run with faster receivers on deep routes.

KU speedster Steven Sims beat Kirby on one of those plays in the fourth quarter, slipping by him for a 60-yard touchdown that made the score 27-20.

When the Wildcats were unable to score on the ensuing drive, the Jayhawks had an opportunity to tie the score, starting at their own 20 with 4 minutes, 37 seconds remaining. K-State responded with an important three-and-out, and McCrane clinched the game with a field goal.

"I was frustrated," K-State defensive back D.J. Reed said, "because we have so much potential in our secondary and just the whole defensive unit and we gave up (more than) 400 passing yards. Last week we gave up 400 passing yards. It's just unacceptable. We have obviously got to watch film, get better and learn from the mistakes that are happening. We have to tighten up our coverage."

K-State needed all the offense it could muster in this one, and moving the ball proved difficult after Delton exited the game following a hard hit late in the second quarter.

"I couldn't be prouder of the defense based on what they had to deal with (field position)," KU coach David Beaty said. "I thought those guys responded great."

The Wildcats turned to Thompson, a redshirt freshman, to close out the game, but they didn't ask him to do a whole lot with his arm. Most of their remaining plays went to Barnes out of a wildcat formation.

"I loved it as a running back," Barnes said. "That is something you always want, to get the rock in crucial situations and run out the clock. I am glad we were able to lean on our running game."

Things seemed to flow easier for KU, as it made it the score 20-13 with a run from Taylor Martin early in the fourth quarter and then 27-20 with the 60-yard bomb to Sims.

The outcome went according to script, but the game did not. K-State led Kansas 10-6 at halftime, but in some ways it felt like the Wildcats were losing.

The Jayhawks played with more energy in the first half, out-gaining the Wildcats 213-197 and regularly crossing midfield. They only managed two field goals off those all drives, but they also pinned K-State at the one with a punt and threw a ball into the end zone on the final play of the second quarter.

K-State countered with a 99-yard kickoff return by Reed for a touchdown in the first quarter, giving the Wildcats a 7-3 lead just 8 seconds after falling behind 3-0

The rest of the first half was entertaining between the 20s and a bore in the red zone.

Neither team scored an offensive touchdown in the first half, with the Wildcats losing a Byron Pringle fumble and turning the ball over on downs on an unsuccessful fourth-down run. The Jayhawks had to settle for field goals.

Things picked up in the second half, but it was close throughout.

For once, K-State had to sweat out the final moments of a Sunflower Showdown.

They'll take it. Relief beats disappointment.

"We need to learn how to enjoy a win," K-State right tackle Dalton Risner said. "There are a lot of things we could have done better today, but whenever we are 3-4 and we get a win like this ... We could have gotten upset today. I'm really glad that didn't happen."