Two years ago, when the Phillies dove headlong into the free-agent pitching waters, they identified two starters whom they believed possessed untapped potential that exceeded their past performance.

One of them was Zack Wheeler.

The other: Kyle Gibson.

Funny, isn’t it, how things work out? The 33-year-old Gibson, acquired a week ago in a trade-deadline deal with the Texas Rangers, will make his first home start for the Phillies on Friday night in the opener of a first-place showdown with the New York Mets; Wheeler will start the series finale Sunday.

The Phillies pushed for Gibson in free agency. And when he took the Rangers’ three-year, $28 million offer in late November 2019 -- a few days before the Phillies signed Wheeler to the third-largest free-agent contract in club history (five years, $118 million) -- several team officials presumed the Indiana native, University of Missouri product, and former Minnesota Twins first-round pick simply preferred to play in the Midwest.

“Quite frankly,” Gibson said the other day, “it came down to comfort with a team dietitian.”

» READ MORE: J.T. Realmuto, Rhys Hoskins deliver huge two-run doubles in the ninth inning and other observations from Phillies’ 7-6 victory over Nationals

Midway through the 2019 season with the Twins, Gibson was diagnosed with ulcerative colitis, an inflammatory bowel disease that affects the colon and rectum. He developed the condition after getting sick with E. coli during an offseason trip with his wife to the Dominican Republic. At its worst, he said it kept him awake at night and caused him to go to the bathroom “15 to 18 times a day with a lot of upset stomach.” He lost about 20 pounds. He changed his diet, then changed it again. Anything to feel better.

Somehow, though, Gibson pitched through it for months. He made 29 starts for the Twins that year, all but two before he finally succumbed to the injured list for two weeks in September. He saw specialists after the season and received medication to relieve the symptoms and manage future flare-ups.

But when the time came to test free agency, he knew he had to consider more than geography, or a chance to win a World Series, or even money.

“My wife went through so much during those four months, because even when I was there, she was a single parent for a lot of the day because I really wasn’t able to be present,” Gibson said. “I wasn’t sleeping at night, so I tried to rest during the day as much as I could, and it put a lot of stress just on the household.

“I talked to my wife and said, ‘If I don’t feel good for the next three years, it doesn’t matter what team we’re with.’ That’s kind of what it came down to.”

The Rangers, as it turned out, knew all about what Gibson was going through. Jake Diekman, the former Phillies reliever who was traded to Texas with Cole Hamels in 2015, dealt with ulcerative colitis since childhood before having surgery to remove his colon in 2017. Gibson met with Rangers team dietitian Stephanie Fernandes and trusted that she could help him develop a plan to keep his stomach issues in check.

“They had a lot of experience dealing with three or four players with ulcerative colitis like I had,” Gibson said. “I kept, I called it my ‘food and poop log,’ so I could figure out what I ate that made me feel worse or better. I still have it on my phone, and I can look back and appreciate, one, how far I’ve come and where I’m at today, but also remember the things that I was trying and the people that were trying to help out.”

Before the illness, there was reason to believe the Phillies’ front office was right to be bullish about Gibson.

From the All-Star break in 2017 through mid-June 2019, when his ulcerative colitis really started to get bad, he posted a 3.67 ERA in 58 starts, averaged six innings per start, and had a 22.4% strikeout rate. During that 23-month span, his 49.6% ground-ball rate was fifth-best in baseball and nearly as good as Aaron Nola’s (50.2%).

“That was probably as consistent as I’ve felt in a two-year stretch,” Gibson said. “Going into free agency, I think that’s what teams looked at more. My stomach issues weren’t really public knowledge for the most part, which might have hurt me a little bit. But I wasn’t looking for that to be an excuse to why I wasn’t pitching well.”

» READ MORE: Andrew McCutchen hopes to return to Phillies' lineup next week

It was a big factor, though. And Gibson struggled last year in his first season with Texas. He said he didn’t have a full offseason to train because he was being treated for his stomach problems. Once the pandemic hit, he needed to be extra cautious because he was at higher risk for COVID-19. He made 12 starts in the shortened season and posted a 5.35 ERA.

But it has all come together this year. After getting knocked out in the first inning on opening day, he reeled off 15 consecutive starts in which he pitched into the sixth inning and compiled a 1.51 ERA. He pitched for the American League in the All-Star Game. And with the Rangers buried in last place in the AL West, he became a sought-after trade candidate, albeit in a tepid starting-pitching market.

The reason for his success: Better health, Gibson said, has bred an increase in confidence.

And now, two years after the Phillies targeted him and with one year (and $7 million) left on his contract, he will start the most important series of the season so far. He gave up two runs on five hits and threw 113 pitches in 6 2/3 innings in his Phillies debut last Sunday in Pittsburgh. They will gladly take those results every five days.

“I think there’s been times where I pitched up to probably about as high as my potential was, but I never had 15 or 16 starts like I had this year where I put it together,” Gibson said. “Who knows what the next 10 starts or the next year-and-a-half is going to be? But what this has allowed me to do is it’s allowed me to see maybe the pitcher that I thought was in there.”

It’s the pitcher the Phillies targeted two years ago.