Alexander Mendoza, known as "El Porky", had just arrived for a trial hearing in El Progreso, escorted by security forces, when the attack took place.
At least four officers were killed and three others were wounded.
MS-13 is one of the most violent criminal groups in Central America.
President Juan Orlando Hernández offered a reward of 2 million lempiras (£62,000; $80,000) for information that leads to Mendoza's recapture.
- The story behind MS-13
- 'Why I'm leaving Honduras'
Police said at least 20 gunmen took part in the operation on Thursday afternoon in El Progreso, around 30km (18 miles) east of Honduras' second city, San Pedro Sula. One of the suspects also died in the attack.
A video said to be from the court's CCTV, and aired by Honduras' HCH broadcaster, shows a handcuffed man wearing a white tank top, believed to be Mendoza, being carried into the building by security forces. Moments later, armed men wearing similar uniforms arrive and force people into rooms.
After a few minutes, the man in the white tank top reappears, without the handcuffs and carrying what appears to be a machine gun and a pistol, trying to leave the building with a group of gunmen. A shootout between them and security forces, who were outside, unfolds.
The footage ends showing 11 men and the person believed to be Mendoza fleeing.
It was not clear how the operation to free Mendoza, who was reportedly on the second floor awaiting the start of the hearing, unfolded inside the building. Police officers and other authorities have previously been accused of involvement with criminals.
Separate footage broadcast by local media showed the men climbing into several vehicles and escaping.
Deputy Minister of Security Luis Suazo said: "We're going to recapture this man and arrest those who helped him escape."
Local media reported the group then abandoned their vehicles and weapons in a nearby neighbourhood. The body of the group member who died was left in a red van.
Mendoza, considered one of the most important of the gang's leaders, had been captured in 2015 and sentenced to 20 years in jail in 2018, for illicit association and money laundering. He was awaiting trial for several murders.
MS-13, or Mara Salvatrucha, was created in the 1980s in Los Angeles by poor mostly illegal immigrants who had escaped from the civil war in El Salvador.
When the conflict ended, with a peace treaty signed in 1992, many of those who were already in jail were expelled and deported to their country, or their parents' country in many cases.
They took LA's gang culture back to Central America, and the group spread to El Salvador, Honduras and Guatemala. In recent years, thousands of people have fled those countries, many of them trying to reach the US, saying they were victims of violence and persecution.