K-State led 68-59 with 1:53 remaining in regulation, but the Jayhawks went on a 10-1 run to tie the score, capped by Andrew Wiggins' tip-in with 7 seconds left.
Foster's 3-point play with 3:20 to go in the ensuing overtime put Kansas State ahead to stay and the Wildcats (17-7, 7-4 Big 12) held on to avenge an 86-60 thrashing absorbed last month in Lawrence.
Will Spradling donated 15 points, six rebounds and five assists as Kansas State won a second straight against a ranked opponent.
The Jayhawks (18-6, 9-2) got 19 points and 11 rebounds from Perry Ellis and 16 from Wiggins.
Naadir Tharpe had a double-double of 13 points and 10 assists.
Beautician charged with giving client fatal silicone butt injection
Duggar sisters unveil Christian dating rules in new book