Club skipper Gray and McGregor were both out of contract at the end of the season, but head coach Paul Heckingbottom revealed he was keen to keep experienced players who he sees as influential members of his squad.
Although Gray turns 31 next month and McGregor will be 34 in August, Heckingbottom insisted the pair remain an integral part of his first-team plans.
He said: “I’m really pleased that we’ve been able to agree new contracts with Darren and David but, in reality, it was a quick conversation on both sides.
“We’re fortunate to have two experienced players of real quality and I have spoken repeatedly about their qualities as leaders and role models within our dressing room.
“From their perspective, this club clearly means the world to them and it can only be a good thing that they will continue to help shape it over the next four years.
“Be in no doubt, they are first team players. The challenge, for the pair of them, is to maintain that for as long as they can.”
Lifelong Hibs supporter McGregor, who has overcome two cruciate ligament injuries in his career, said: “Walking through that door four years ago was a dream come true.
“When I was 24 and folding jeans for a living in Xile, if you’d told me at 30 I’d be playing for Hibs, winning the Scottish Cup and having such a big influence in the team I’d have shaken my head in disbelief. If you work hard, the sky is the limit.”
Gray – of course – scored that winning goal against Rangers at Hampden three years ago, having become former boss Alan Stubbs very first signing for the club, spending his first three seasons playing in the Championship.
He said: “It’s been a fantastic five years since I’ve been at the club and I’ve enjoyed every minute of it.
“It’s a really good place to be at the minute and an exciting time. The club is in good shape.
“The hunger to play football is driving me on and hopefully that will carry me through another four years.”
George Craig, Hibs’ head of football operations, believes tying Gray and McGregor up on extended contracts was an important move in helping take the club forward.
He told the club’s website: “It’s fantastic news. We’re securing the services of two excellent professionals.
“One of the things I’ve said consistently since coming to the club is that we’re very lucky that our senior professionals are great role models for our younger players. They’re terrific in everything that they do.”