Selby, who was the 2014, 2016 and 2017 champion, is ranked second in the world – 30 places above Wilson.
But Wilson, who has journeyed on a long road to join snooker's elite, produced another Crucible surprise after amateur James Cahill stunned world number one Ronnie O'Sullivan earlier this week.
— World Snooker (@WorldSnooker) April 27, 2019
Selby resumed 9-7 behind but he looked likely to progress after winning the first two frames of the final session.
Wilson, however, kept his nerve as the pair exchanged the next two frames.
And the 33-year-old from Tyneside rattled off the next three frames for a 13-10 victory.
Wilson finished with a flourish as a final break of 92 ended Selby's hopes of a fourth world crown and set up a quarter-final date with Ali Carter or Zhou Yuelong.
Welshman Williams had trailed Gilbert 5-3 on Friday afternoon before feeling pains in his chest.
Williams subsequently posted on Twitter that he was in the A&E department of a local hospital, saying: "Couldn't stick the chest pains no more."
The 44-year-old, who made his own way to hospital, later posted: "Doctors are confidant (sic) it's not anything to do with my heart. Awaiting more tests at 10 o clock."
But Williams took his place in the morning session, entering to huge cheers from the Crucible crowd and the Queen song 'Don't Stop Me Now'.
Gilbert started with an 82 break to extend his lead to 6-3, but Williams won the next two frames to cut the deficit to one.
But the Englishman responded with a 100 break and won the next frame 72-47 to lead 8-5.
Williams fought back with breaks of 86 and 101 to again cut the gap to one.
But Gilbert extended his advantage ahead of the final session on Saturday night to leave Williams with plenty of work to do.