Messi, who has been sidelined since sustaining a knee injury against Las Palmas on September 26, was joined by Ivan Rakitic, missing since November 4, for Monday's session, according to Barca's official website.
The Argentine superstar was expected to miss the weekend's crunch clash at the Santiago Bernabeu but his involvement in training will raise Barca hopes that he could be set for a timely return from injury.
The Catalans can establish a six point lead over their rivals with victory in the capital and a fit Messi, alongside Luis Suarez and Neymar, would make Luis Enrique's side firm favourites for the match.
Earlier on Monday, Barca B coach Gerard Lopez revealed Messi had been training with his squad and said he had seen positives signs from the 28-year-old.
"Leo completed training. He looked good and I am glad that the recovery is positive," Lopez said, according to Sport.
"He looked happy and lively.
"Messi adapted to our training and even helped with tactical aspects to prepare the team," he said.
"I am delighted that we could have him for two sessions and that he didn't have to lose two days of recovery work."