The British duo last won the Madison together in 2008, and their success on the final day of competition earned Britain a fifth gold medal leaving GB top of the standings with five golds, one silver and three bronze medals.
Having held off France and a crash for Cavendish 11 laps from them end, this was a repeat of their success in Manchester eight years ago.
Mark Cavendish (L) and Sir Bradley Wiggins (R) of Britain celebrate winning the men's madison final on the podium.
It was Cavendish's third world title at the Madison 11 years after his first in Los Angeles.
When we went we had to give everything," said Cavendish. "I hit my head hard so I was a bit dizzy, but I just wanted to get back on and finish with Brad. It could be my last one (world championships) so it's just perfect to go out like this with Brad.
Former Tour de France winner Wiggins will chase a sixth Olympic gold in Rio.
"You couldn't have written a better script. It's so nice to be world champion again."
It brings everything together for them. It’s a special moment for the guys and the team. What a spectacle."
Emotional Wiggins and Cavendish collect golds in madison
The two British cycling greats, who briefly fell out when they flopped as favourites for the 200-lap event at the 2008 Beijing Games, came from nowhere to carve their way to victory and give the hosts a table-topping fifth gold medal.
It was the icing on the cake for the host nation who, after a wobbly start to the championships, ended with nine medals and crucial momentum ahead of this year's Rio Olympics.
A year ago in Paris they returned without a single rainbow jersey to show for their efforts.
Wiggins: It was my last race on this track, so it wasn’t bad, was it!
Britain's first Tour de France champion Wiggins, 35, has returned to his track roots for a golden swansong by the Copacabana this year, and how he revelled in the fast and furious action always guaranteed on the boards.
He was disappointed to miss out on gold in the team pursuit earlier in the week, while 26-times Tour stage winner Cavendish's hopes of making the British track team this summer are still in the balance after omnium disappointment.
But what a show they provided as they hunted down the leading teams in relentless fashion to win gold, eight years after they did the same in Manchester.
"That was my last race on this track...and it wasn't a bad one," Wiggins, who celebrated by kissing it, said.
A partisan home crowd produced an ear-splitting din as the British duo, working like clockwork with Spain, gained back the lap they had lost early to France, Switzerland and Colombia.
Cavendish even had to pick himself off the boards after a late crash, but by that time Wiggins had the race under control and, with points already in the bag, it was a matter of ticking off the laps.
"It's one of the last times we'll ride together. That's incredible," Cavendish, who must wish the Madison was still an Olympic event, said as the crowd saluted them.
"We're world champions again, we've done it again."
Cavendish will now have to sweat on a place on the plane to Rio, where he hopes to win a long-overdue Olympic medal, after missing his target of an omnium medal on Saturday.
France, so impressive last year on home soil, failed to win a gold medal after their Madison team Morgan Kneisky and Benjamin Thomas were swallowed up by the Brits and had to settle for silver ahead of Spain.
Ten nations won golds with Germany second in the medals table and Australia third.