Pat Clarke struck a late winner as Raith came back from a goal behind three times to defeat Berwick 4-3 in the Scottish Communities League Cup first round.
Berwick went ahead after nine minutes when Lee Currie struck an unstoppable free-kick.
Raith drew level in the 25th minute when Brian Graham converted Joe Hamill's inswinging corner.
The away side restored the lead early in the second half thanks to Phillip Addison's 18-yard effort.
Raith hit back eight minutes later as Douglas Hill headed home Allan Walker's corner, but parity was short-lived as Currie produced another wonderful free-kick from 25 yards.
The home side equalised again with 17 minutes to go, Graham curling in from 12 yards before Clarke's close-range finish won the game.