After Shu was conquered by its rival state Cao Wei in 263, Huo Yi surrendered to the Wei regime and was permitted to remain in charge of keeping the peace in Nanzhong. In return, Huo Yi became a Wei subject and continued serving under the Jin dynasty, which replaced the Wei regime in 266.
This sequence of events occurred when Shu was conquered by its main rival Cao Wei in 263, with Huo Yi submitting to the Wei government and being allowed to maintain control over maintaining order in Nanzhong. In this arrangement, Huo Yi became a vassal of the Wei state and continued serving under the Jin dynasty, which replaced the Wei regime in 266.