WA returned for the final day at 8-351 needing six more runs to win but Tasmania required just two wickets, however, Cockley faced all eight deliveries from Ben Hilfenhaus and James Faulkner in the morning.
Despite young all-rounder Ashton Agar standing at the other end not out 71, it was Cockley the hero to score the last seven runs with the victorious boundary coming off the bowling of Faulkner on the eighth ball of the day.
Hitting the winning runs completed a remarkable return to first-class cricket for Cockley. The pace bowler played 10 Shield games and five one-dayers for NSW between 2008 and 2009 before a horror injury run.
While on tour with Australia, he injured his back and then on the comeback from that hurt his knee requiring a full reconstruction. That got infected and at one point he looked likely to lose his leg, so the 26-year-old was just delighted to be back with his adopted state.
"It's been quite a big week for me to debut in the one-dayer and be named in the Shield team, and to get a win like that. I'm still buzzing at the moment and I can't describe the feeling," Cockley said.
"This means a bit more to me just because of what I've been through with injuries. I had three and-a-half years out of the game and I didn’t expect to get back after my leg so to work hard and get back, and make the move here for a fresh start and have a week like this is very satisfying.
"To be quite honest, I was thinking being out there was better than being in a hospital. I didn’t expect to get back so I just wanted to go and play cricket, and enjoy it. I really wanted to get it over and done with as quickly as possible this morning."
It completes a remarkable turnaround by WA after they were bowled out for a paltry 97 in their first innings with Tasmania scoring 211 and 242 either side of that to set the Warriors 357 to win.
That looked near impossible when WA slumped to 3-37, but then fighting knocks from John Rogers (39), Michael Hussey (44) and Mitch Marsh (51) at least got the Warriors within some form of striking distance.
There was still plenty of work to do at 6-203 when Marsh was out, but then Sam Whiteman and Agar put on 121 for the seventh wicket in the biggest partnership of the match.
Whiteman was out late on the third day for 83, the highest score of the match, and then Ryan Duffield fell soon after for 12 before WA was 8-351 when stumps was called.
WA pulled off the run chase on the final day's morning, though, making it the first time the home side has made less than 100 in their first innings to bounce back and win a Shield match at the WACA.
It is also WA's third highest ever successful run chase in Perth and keeps Justin Langer's men within a chance of making next month's Shield final.
Tasmania's hopes of reaching the final are now over with the loss.