The 23-year-old striker, who joined the academy ranks in east London from Solihull Moors in 2018, was introduced in a deeper role than he's used to by David Moyes when sent on for Tomas Soucek.
Afolayan showed great awareness to time his run into the box and finish after Ryan Fredericks drew a save from Ellery Balcombe which fell at the feet of the young Hammers sub.
Afolayan, who played against Tottenham for the U23s on Friday night, said: "I am delighted - it is a dream come true.
"It has been a couple of years of hard work since I joined the club.
"I thought Ryan (Fredericks) was going to square it but he had a shot and I just followed it in.
"I played 60 minutes last night for the U23s. When I came off I got told I was in the squad for today.
"I just had to go home and prepare. All I can do is come in every day and work hard and pray I get opportunities and take them.
"I have played in the FA Cup before. To score in the fourth round here is a dream."