Abouelkassem lost the final 15-13 to his Chinese rival and settled for silver, the first Olympic medal ever claimed by a fencer from Africa.
Lei's first gold at a major event topped his silver at the 2010 world championships in Paris and gave China only its second ever Olympic title in men's fencing.
"I did not expect to win a medal," the 28-year-old Lei said through an interpreter. "I was well prepared and full of confidence, so maybe that worked in my favour today."
Abouelkassem, who plays left-handed, asked for medical treatment on his left arm at 4-2 down in the final. He resumed the match after five minutes and came close to winning gold after taking a 13-11 lead.
"I had a problem with my left shoulder before the match," he said. "Then I had the cramp in the whole left hand. My pointing wasn't very good. It was very hard to win."
Still, he could barely believe what he'd achieved, dedicating the medal to his father who died recently.
"This was the dream of my dad and he left me three months ago," he said.
Choi Byung-chul of South Korea won bronze after edging Andrea Baldini 15-14, denying the multiple European and world champion from Italy the Olympic medal he's still lacking.
Baldini missed the 2008 Beijing Games amid a doping case but was later cleared of the charges.
The 21-year-old Abouelkassem finished fifth at last year's world championships for his previous best result at a major competition.
Abouelkassem, son of an Algerian mother and an Egyptian father, said his victory would not just boost fencing in Egypt, but in all over Africa.
"They need this medal to improve the fencing in Africa," he said.
On his way to the final, Abouelkassem beat reigning world champion Andrea Cassara of Italy and former four-time world champion Peter Joppich of Germany.
"Every match, I am better than the match before," he said after defeating Cassara. "I feel good, I have no stress, I am from Africa, from Egypt, so no one expects me to win."
Like his Italian teammate Cassara, top-seeded Valerio Aspromonte missed out on the semifinals after losing 15-8 to eventual champion Lei.
Earlier, Aspromonte beat Sebastian Bachmann 15-11, but went 11-8 down against Radu Daraban of Romania before reeling off seven straight points.
Bronze medallist Choi said after beating Ma Jianfei of China 15-13 that the disputed semifinal defeat from Shin A-lam in the women's individual epee on Monday "had a big effect" on the South Korean team.
Shin lost the match 6-5 to Germany's Britta Heidemann, but not before officials rejected an appeal by the South Koreans, claiming that the match was already over when Heidemann scored the winning point in the final second.
"It was psychologically very difficult," Choi said. "I personally couldn't sleep tonight. I went to bed at 11 and couldn't sleep until three o'clock in the morning. Shin A-lam definitely should have won."
Germany lost its two main medal hopes before the quarterfinals. Defending champion Benjamin Kleibrink was routed in his opening match 15-5 by Yuki Ota of Japan before Joppich went out against Abouelkassem.
"My dream is over, I am very disappointed. I came here to win," said Joppich, adding that he was now going to concentrate on the men's foil team event on Sunday.