Jim Walmsley ran the Western States 100 (WS100) mile (160km) ultra marathon in a record 14 hours 30 minutes, 16 minutes faster than the previous record, but with only a few miles to go his chance was almost ruined by a family of bears.

Walmsley had just passed the turning where he famously got lost in 2016, costing him the record on his first attempt, and flew around the corner into two cubs and their mother.

“I just caught them off guard and the two little cubs darted up a tree, so the mama bear wasn’t going anywhere,” he said.

Walmsley tried yelling and even throwing some rocks to shift the bear. It got up on it’s hind legs and forced Walmsley to back off.

“I was yelling in frustration,” he said. “I couldn’t believe it was happening. This is happening today? I’d finally put myself in a position to set the record. I thought, I can’t get a break at the Western States.”

The bear shifted behind a tree and Walmsley made a break for it, passing the animal by only a few metres.

Jim Walmsley cools Western States record talk and plans steady pace after 2017 burnout in brutal California heat

Walmsley made headlines when he publicly declared he would not just set the course record in 2016, but run the 160km in under 14 hours. He was on track until he got lost painfully close to the end. He returned in 2017 with the same aim but overcooked it in the heat and had to drop out.

This time, he was determined to run conservatively.

“I made it through Robinson Flat (48km) with the splits I wanted,” he said. “It was slower than record pace but it gave me a chance to deal with the heat. That’s when I started getting into a rhythm, but I still wanted to be a cautious in the canyons.”

Runner brings beer for Western States ultra marathon fuel to settle stomach in heat on world famous 100 miler

The canyons at the base of Devil’s Thumb (75km) and Michigan's Bluff (88km) are notoriously hot and have sapped the energy of many athletes.

Hong Kong trail runner ranked top 10 at Lavaredo but must run his own race amid world class field

“It wasn’t until mile 90 (144km) that I stated doing the maths and realised I might have the record,” he said. “It wasn’t until late that I started getting hungry for the record. I’d just run within myself.”

The first women over the line was Courtney Dauwalker, setting the second fastest women’s time ever in 17:27.

Walmsley has an impressive running resume, but had thus far under performed at the 160km distance. Aside from his two previously WS100 races, he had also run the 160km Ultra Trail of Mont Blanc (UTMB), where he comfortably led until around halfway. But when eventual winner Francois D’Haene applied pressure, Walmsley dropped down the pack.

Hong Kong Four Trails survivor aims for Western States double finish with crew he met on Twitter

D’Haene was racing this weekend at the WS100, but he came second almost an hour and a half behind Walmsley.

“Last year [UTMB} was awesome and cool, and such a big learning curve but certainly this WS100 is a big confidence boost,” he said. “The main thing is I finally got a 100 mile win.”

Walmsley is returning to the UTMB in Chamonix this August.

The UTMB is a different beast, Walmsley said, because it has more climbing, it runs through the night and is at altitude.

“You can see the difference just in the difference between Francois and me there and here,” Walmsley said.

Francois d’Haene runs Jim Walmsley into the ground and leaves Kilian Jornet in his wake to seal third Mont Blanc victory

Many athletes have become legends via multiple wins at the WS100, but Walmsley believes that if he had merely won he might have to return, but the record is a monkey off his back.

“I have a lot of goals,” he said, adding he will keep his place for next year’s WS100 and decide later whether to return. “There are too many things on the bucket list.”