Bonilla, who successfully defended his European title in Manchester earlier this year, was pushed all the way by Sweden fighter Uno Sanli, who led 5-4 after the first round.
But the Spaniard landed a winning score just seconds before the buzzer at the end of the regulation three rounds to record a 7-6 victory.
There was, though, no such problem for defending Olympic champion Wu Jingyu in the women's -49kg, as the Chinese fighter cruised past Elizabeth Zamora Gordillo of Guatemala 10-2. She will fight Japan's Erika Kasahara this afternoon for a place in tonight's semi-finals.
A new scoring system is being used for the first time in Olympic competition, and both fighters in the contest between Mexico's Diego Garcia de Leon and Safwan Khalil of Australia used the appeals process, with scores being removed on video review.
Khalil, the number eight seed, went on to close out a 9-4 victory after a strong third round to set up a clash with Bonilla in the quarter-finals.
Compatriot Yang Shu-Chun, world silver medallist in 2011, progressed in the women's competition with a comprehensive 9-3 win over German Sumeyye Manz, the world bronze medallist. She will fight Chanatip Sonkham, the seventh seed from Thailand.
Spanish third seed Brigitte Yague Enrique, the three-time world champion who missed a shot at gold in Beijing because of injury, progressed to the last eight when she dispatched Carolena Carstens Salceda of Panama 7-2.
The repechage offers the chance of redemption later for anyone defeated in the preliminaries, should their opponent go on to make the finals.