AP photo by Steve Helber / Martin Truex Jr. celebrates with a fan after winning a NASCAR Cup Series race Sunday at Martinsville Speedway in Martinsville, Va.

MARTINSVILLE, Va. — Martin Truex Jr. admits to being surprised by his success at Martinsville Speedway.

Truex won a stirring, laps-long duel for the lead with Joe Gibbs Racing teammate Denny Hamlin in the rain-delayed NASCAR Cup Series race Sunday night, winning for the third time in the last four visits to the 0.526-mile oval — the oldest and shortest track on the circuit — that is known as the "Paperclip."

That nickname, a description of the speedway's shape, brings to mind an office. Martinsville is something else for the 2017 Cup Series champion, whose trio of career wins there have come in a three-year span.

"This place has become a playground for us, I guess," the 40-year-old Truex said in victory lane. "We didn't have the best car all day, but we just kept working on it and never quit on it."

Truex, who nudged Hamlin repeatedly in the turns and tried to get to his inside on the straightaways without success, finally made the pass with 15 laps to go, ducking underneath Hamlin coming out of the second turn. He sailed off to victory without another challenge as Hamlin and Hendrick Motorsports' Chase Elliott battled the rest of the way for second.

Truex became the first repeat winner in NASCAR's top series this season.

The race was rained out after 42 laps Saturday night, and it was completed Sunday as the second part of a doubleheader that started with the completion of the rain-delayed Xfinity Series race from Friday night.

Elliott, who won at Martinsville last November on his way to winning the season championship, held off Hamlin for second in the No. 9 Chevrolet. Hamlin was third, followed by William Byron and Kyle Larson, both of them Hendrick drivers.

"That was a lot of fun there at the end, racing with Denny," Truex said. "We raced clean, and we were able to come out on top."

JGR had all four of its drivers finish in the top 10 as Christopher Bell took seventh and Kyle Busch 10th, leaving team owner Joe Gibbs excited — and relieved.

"I was just praying that Denny and Martin didn't get together running up front," said the NASCAR Hall of Famer.

The outcome was not only disappointing for Hamlin, whose Toyota was dominant as he led 276 laps, but also for Ryan Blaney, who won the first two stages and led 157 laps but dragged an air gun out of his pit after the final stop and was sent back to 19th in the field.

Blaney rallied to finish 11th in the Team Penske No. 12 Ford, but earlier, he and Hamlin were setting the pace.

Blaney passed Hamlin for the lead on the 75th lap and cruised to victory in the 130-lap first stage, and the second stage played out much the same. Hamlin was fast early in the run, pulling comfortably ahead, but Blaney eventually ran him down to win that stage, too.

Hamlin's third-place finish was his series-best seventh top-five run in eight races this year.

"We had a really fast car for 20 laps or so, and then it would just kind of go away," Hamlin said. "We just continue to run top three every single week. Every stage, every finish — we're right there. We just need to get a little better. We're barely missing it."

The race featured several drastic changes in fortunes, perhaps none bigger than for Joey Logano. The Penske driver was in danger of being lapped at the end of the first stage, but he gambled with others midway through the race by staying on the track to gain position when most of the leaders pitted.

It worked because another caution flew shortly thereafter, allowing him to pit for the fresh tires most other teams already had, and he stayed near the front the rest of the way to finish sixth.

Misfortune was the case for Alex Bowman, Brad Keselowski and several others because of a major pileup on the back stretch involving more than a dozen cars on lap No. 387. Bowman had risen as high as second before getting caught up in the mess that ended his time on the track, and Keselowski, a two-time winner at Martinsville, also had to call it a day after the collision.

"It's just part of the short-track deal," said Keselowski, who had been excited about the series' three-race run at such layouts, with Martinsville following the dirt race at Bristol Motor Speedway and the next stop at Virginia's Richmond Raceway.

The trouble started when Kyle Busch and Chris Buescher got together exiting the second turn.

Daniel Suarez also was involved, and he rode around the oval to the entrance to the first turn, climbed out of his car when it caught fire and walked away as it burst into flames.