"It's wonderful," said Francisco Lopez, 67, seated at a table decorated with red ribbons in the courtyard of the Cybele Palace, a monumental wedding-cake shaped building that houses Madrid city hall.
"If I hadn't been invited to come here tonight, I would have just eaten a sandwich," added Lopez, who has been sleeping in a church for the last months because he has nowhere to live.
Madrid city hall, run since June by a left-wing alliance backed by Spain's anti-austerity party Podemos, allowed a Spanish NGO to host the Christmas Eve dinner in the building.
Madrid mayor Manuela Carmena, a 71-year-old former judge who was a labour rights activist during the dictatorship of General Francisco Franco, mingled with the guests.
"Merry Christmas, much joy to everyone and, on this day, peace," she said as she delivered a toast before leaving to have dinner at home with her family.
A local taxi company offered free rides to dinner guests who were seated at 22 tables under the beautiful glass skylight of the courtyard.
A giant, environmentally-friendly Christmas tree made from cardboard boxes decorated the courtyard, with a star made from used plastic bottles glimmering on its crest.
Father Angel Garcia, the Roman Catholic priest who founded the Mensajeros de la Paz (Messengers of Peace) NGO that hosted the gathering, said the goal was "to make these people happy, give them love and affection...
"That at least one time a year, for some of them the first time in their lives, they can sit at a table with flowers, with red napkins."
No alcohol was served but in addition to water and soft drinks the diners were served "champin", an alcohol-free sparking beverage made of fruit juice that is often served at children's parties in Spain.
About 60 people volunteered at the dinner, helping to prepare food and serve dishes, instead of celebrating Christmas Eve with their own families.
"Its better like this. When you are more fortunate, you have to help," said one of the volunteer, 16-year-old Andrea Fernandez, as she helped set up tables before the start of the meal.
At the end of the dinner party bags full of nougat and other traditional Christmas sweets were given to the guests to take away with them.
Mayor Carmena campaigned for a May local election on a pledge to fight inequality and help the city's poor.
Since taking office she and her team have helped overturn eviction orders for dozens of families and set up a mediation service for people who cannot pay their mortgages.
Carmena's efforts to help the homeless won her words of praise from US actor Richard Gere, who said last month during a stop in Madrid he "applauded" the mayor for her "humane and intelligent" approach to tackling the issue.
Gere was in the Spanish capital to promote his latest film, "Time Out of Mind", in which he plays a homeless man.
Carmena's stance stands in stark contrast to the positions adopted by the conservative Popular Party which ruled the Spanish capital for over two decades.
Her Popular Party predecessor Ana Botella once famously complained that homeless people were an "added difficulty" for street cleaners.
The Popular Party's candidate in the May local elections, Esperanza Aguirre, a countess by marriage, promised during the campaign to prevent homeless people from sleeping in the streets in the centre of Madrid, saying they "drive off tourists".
Madrid has about 1,900 homeless people, according to city hall figures. About 40 percent sleep on the streets, with the rest spending the night in shelters.