AMES, Iowa -- On a rainy day at Jack Trice Stadium on Saturday, the fifth-ranked Kansas State Wildcats didn't exactly open their game with Iowa State with a display of thunder and lightning.

For the second straight week, the Wildcats came out sluggish in the first half to take a narrow lead as the teams went to the halftime locker room. Unlike last week's second half blowout of Kansas, however, K-State was forced to fight to the end to escape with a 27-21 victory over Iowa State in a Big 12 Conference game.

"I would have liked for us to have played better than we did across the board," K-State coach Bill Snyder said. "There were times when we played extremely well. I think Iowa State played extremely well. … By the same token, we still had some issues. It was out of character for us to be a highly penalized team and we were."

Penalties were costly for the Wildcats in the game. K-State came to Ames with just nine penalties in fives games on the season and were flagged for nine penalties in this game alone.

"It was very crippling," junior linebacker Tre Walker said of the penalties. "We are not known for making penalties, and that killed us today. … We just can't make those penalties because that can allow a team to stay in the game and it allowed Iowa State to stay in the game today."

A record crowd of 56,800 caused part of K-State's issues. K-State also fought communication problems with its coaches in the press box during the first half.

K-State quarterback Collin Klein overcame the issues despite using all three first half timeouts in the first quarter due to the communication issues. Klein finished the game with 105 yards on 25 carries and three touchdowns, and completed 18 of 24 passes for 187 yards in lifting the Wildcats to 6-0 on the season and 3-0 in Big 12 action.

"He's a great player, an All-American in my book," said Iowa State coach Paul Rhoads, whose team fell to 4-2 and 1-2 in Big 12 play. "He doesn't get the attention because he isn't flashy and doesn't put up the gaudy numbers that some other college football players do, but he has a 6-0 football team that is ranked in the top five.

"They can play with anybody in the country with arguably less talent on the field than everybody in the Top 10."

Just when K-State took a two-score lead, going up 24-14 with 1:33 remaining in the third quarter, Iowa State answered with a 13-play, 75-yard drive that cut the Wildcat lead to 24-21 with 12:34 remaining in the contest.

One of K-State's nine penalties came on that drive when junior safety Ty Zimmerman was called for controversial pass interference at the two. One play later, Iowa State scored.

"I thought our kids fought the fifth-ranked team in the country tooth and nail. We fought to the very end," Rhoads said.

K-State then responded with an exhausting 14-play drive that took 8:10 off the fourth-quarter clock. The drive, however, fizzled and ended with a 25-yard Anthony Cantele field goal.

Iowa State earned two more offensive possessions, but the K-State defense managed to hold the Cyclones on downs both times enabling the Wildcats to leave with the victory.

"I think we played well defensively, we just didn't play with the consistency we would like to and because of some errors in the kicking game and the offense not moving the ball on a couple of drives, we gave them good field position," Snyder said. "We had our moments, but we certainly had things we'd like to have back."

Since his return to the sideline at K-State, Snyder is now 22-0 when leading at halftime, with this game marking the fifth time in the last four seasons a Snyder-led team has won a true Big 12 road game after leading at intermission.

A big reason why K-State held on for the win was its domination of the game's time of possession, holding the ball for 40:54 of the game compared to 19:06 for Iowa State. In the process, K-State ran 76 plays for 364 yards.

K-State also converted, with much thanks to Klein's running, 8 of 17 third downs in the game.

The game marked a milestone for Klein, with the senior quarterback going over 3,000 career-passing yards and 2,000 career-rushing yards during the first half.

The Wildcats needed their scrappy senior quarterback to help them escape falling behind at halftime.

Iowa State used a 30-yard touchdown pass from Jared Barnett to Ernst Brun to ignite the Iowa State crowd and give the Cyclones a 14-10 lead with 2:27 remaining in the first half.

Klein and the Wildcats, though, made the most of their next possession.

Set up by a 31-yard kickoff return by Tyler Lockett, Klein then found Lockett down the middle of the field for a 45-yard pass that put the Wildcats at the ISU 24. Two plays and two Iowa State offside calls later, Klein eased into the end zone from six yards out to give the Wildcats a 17-14 halftime lead.

K-State opened the game with a 14-play drive that ended in a 41-yard field goal by Cantele. The drive went awry when on a second-and-7 at the ISU 20, offensive guard Keenan Taylor was flagged for a 15-yard tripping penalty.

Iowa State responded by scoring on the first play of the second quarter to cap a 12-play drive that gave it a 10-7 lead, but Klein immediately responded by directing an impressive 12-play, 75-yard drive that ended with him going in from two yards out to put K-State back up 10-7 with 8:18 remaining in the first half.

Snyder is now 4-0 against Rhoads, but the average margin of victory has been just 5.25 points.

"This was a standard Kansas State game, coached by a legendary coach and quarterbacked by a great football player," Rhoads said.

The Wildcats will face their biggest test remaining on their regular-season schedule next week when they travel to Morgantown, W.Va., to face the fourth-ranked West Virginia Mountaineers in a game that will leave the Big 12 with a clear-cut early season leader.