Gilbert confirmed his overall victory in the 117km race finale in which Modolo took out a bunch sprint at the Bird's Nest Piazza ahead of New Zealand's Greg Henderson (Lotto-Belisol) and Edvald Boasson Hagen (Team Sky).
"It was really nice but still stressful for the last lap because with a small gap, small advantage of three seconds, I had to be ready for a gap in the final," Gilbert explained.
"I took the last corner in a really good position and then I saw that it was okay because of the headwind in the last kilometre. I didn't take any risks and it was okay."
The 2012 world champion won a shortened second stage to put on the red leader's jersey and then defended his place at the head of the race despite a strong challenge from Dan Martin (Garmin-Sharp) on Monday's Queen stage to Mentougou Miaofeng Mountain.
The general classification podium remained intact following Stage 5, with Gilbert finishing three seconds ahead of Martin with Esteban Chaves (Orica-GreenEDGE) a further six seconds back in third and also winner of the young rider classification.
"Yesterday it was a very big effort for me," admitted Gilbert. "On the climb of more than 10km normally I would be suffering a lot. I was up there with the best climbers of this peloton so for me it's a big effort and I was really happy about it.
"The Tour of Beijing was a great experience and I'm glad that my name will be in this palmares. It was very special to finish here also with those monuments, those roads are very special."
Without any KOM points on offer Michal Golas' (Omega Pharma Ã¢â¬â Quick-Step) lead in the climber's classification went unchallenged. Orica-GreenEdge were winners of the team classification.
Starting the day at Tiananmen Square, the peloton got racing underway at a fast, hard pace through the streets of Beijing. Taking close to 25km to establish, Tosh Van der Sande (Lotto Ã¢â¬â Belisol) and Laurent Mangel (FDJ.fr) got a lead on the bunch just before the race hit the finishing circuits for the first of 12 laps of Olympic Park.
With seven laps remaining, the pair built a maximum advantage of 3min 15sec over the peloton, dropping to 1min 10sec three laps later.
That lead was then extended to 2min 42sec with 25km remaining, sparking a furious effort from the bunch to chase the pair down. It went right down to the wire with the gap still at over a minute as the bell lap sounded.
Belkin, Garmin-Sharp, Team Sky and Lampre-Merida pushed the pace, shelling their lead-out trains in the process and with 800metres left to race the escapees were finally caught.
Modolo was in prime position leading into the final straight and once he hit the front he didn't look as if he was going to be beaten.
It was the Italian's first win since June at the Tour de Suisse, his eighth for the season and one he was supremely satisfied with.
"I won in Suisse but then I had a bad Tour de France and crashed at the Eneco Tour and struggled," Modolo admitted. "I've been at home training for a month and so to win is hugely satisfying for me and for the team who helped me here."
"We always thought we'd catch the breakaway," he continued. "It was close but it's always difficult for two guys to stay away. We tried to force the other teams to work because the team worked a lot for Rui Costa during the race. I had three guys working for me but they gave me a good lead out."
Stage 5: 117km, Tiananmen Square - Bird's Nest Piazza
1 Sacha Modolo (ITA) Lampre-Merida 2hr 40min 10sec
2 Gregory Henderson (NZL) Lotto Belisol
3 Edvald Boasson Hagen (NOR) Sky
4 Tyler Farrar (USA) Garmin Sharp
5 Moreno Hofland (NED) Belkin
6 Luka Mezgec (SLO) Giant-Shimano
7 Davide Appollonio (ITA) Ag2r-La Mondiale
8 Ben Swift (GBR) Sky
9 Caleb Ewan (AUS) Orica-GreenEDGE
10 Enrique Sanz Unzue (ESP) Movistar
1 Philippe Gilbert (Bel) BMC Racing 17hr 59min 57sec
2 Daniel Martin (IRL) Garmin Sharp 0:00:03
3 Esteban Chaves (COL) Orica-GreenEDGE 0:00:09
4 Rui Costa (POR) Lampre-Merida 0:00:11
5 Sergey Chernetski (RUS) Katusha 0:00:23
6 Warren Barguil (FRA) Giant-Shimano
7 Julian Arredondo (COL) Trek Factory Racing
8 Rinaldo Nocentini (ITA) Ag2r-La Mondiale
9 Rigoberto Uran (COL) Omega Pharma-QuickStep
10 Mikael ChÃ©rel (FRA) Ag2r-La Mondiale 0:00:26