A Border Patrol tactical unit killed the Texas gunman. The elite force has played key roles in the US

Law enforcement personnel near the scene of the shootings at Robb Elementary School in Uvalde, Texas.

(CNN)When gunfire rang out at Robb Elementary School in Uvalde, Texas, officials from Customs and Border Protection were among several agencies joining local and federal authorities at the scene.

It's not unusual: Customs and Border Protection officials can operate within 100 miles of a US border, and have a major presence in many border communities, said Javed Ali, an associate professor at the University of Michigan and a former top official at the Department of Homeland Security.
Uvalde is about 80 miles from the Mexican border and therefore within Customs and Border Protection jurisdiction.
      Authorities are still gathering details on the timeline of events leading up to the massacre, but have determined members of the Border Patrol's elite team -- the Border Patrol Tactical Unit -- fatally shot the gunman nearly an hour after the shooter raided the school.
        Border Patrol is under the umbrella of Customs and Border Protection, in the Department of Homeland Security.
          The teenage gunman came out of a classroom closet and began firing when Border Patrol agents entered the room more than an hour after the shooter began his rampage, a source familiar with the situation told CNN Friday. The agents were part of a team that fatally shot the gunman, ending an attack that left 19 fourth-graders and two adults dead Tuesday afternoon.
          Before the assault on the shooter, a group of 19 law enforcement officers stood in a hallway outside the classroom and took no action as they waited for room keys and tactical equipment, a state official said at a news conference.

          What's BORTAC?

          The US Border Patrol Tactical Unit (BORTAC) was formed in 1984.
          It was initially created in response to rioting at Immigration and Naturalization Service detention facilities, according to Customs and Border Protection officials.
          It has since evolved into a highly trained tactical unit with operations both nationally and internationally.
          "BORTAC is unique in that it provides a global response capability. The unit has conducted training and operations with foreign and domestic law enforcement and military entities throughout the United States and around the world, including support of Operation Iraqi Freedom and Operation Enduring Freedom," Customs and Border Patrol said.

          It's the equivalent of a SWAT

          To be a part of the Border Patrol Tactical Unit is no small feat. The course lasts a month and candidates must pass grueling tests similar to the US Special Operations Forces' selection courses. They have physical tests, including pushups, treading water, advanced weapon skills, defensive tactics, and airmobile operations.
          It's now considered the global special response team for the Department of Homeland Security's Bureau of Customs and Border Protection. Ali compared it to elite Special Weapons and Tactics (SWAT) teams, the militarylike units within US police forces, using specialized or military equipment.
          "Its mission is to respond to terrorist threats of all types anywhere in the world in order to protect our nation's homeland. Its agents are counted among the nation's most dedicated and highly trained special operators," Customs and Border Protection says.
          People leave the Uvalde Civic Center following the shooting at Robb Elementary School.

          It's been part of high-profile operations in the US

          BORTAC has played a key role in major US operations.
          During the 1980s, it worked with the Drug Enforcement Administration in the war on drugs in the United States. In the 1990s, it was deployed to Los Angeles after rioting broke out during the Rodney King trial. In April 2000, it was part of the raid at a Miami home that returned Cuban refugee Elian Gonzalez to his family.
          And in the wake of the September 11, 2001, attacks, BORTAC officials were deployed to help secure high-risk areas nationwide.

          Customs and Border Protection has a local office in Uvalde

          Like many Texas towns in the border area, CBD has a checkpoint in Uvalde. It oversees 3,000 square miles of South Texas and conducts traffic checkpoint and freight train check operations. Secretary of Homeland Security Alejandro N. Mayorka said some of the agency's officials live in Uvalde and surrounding communities.

          It provides a supporting role

          In incidents like the one Tuesday, where local authorities are in command of the scene, Border officials often serves in a support role and the agency on command will dictate what they do, a source told CNN, adding they try not to overrule the authorities.
          While the team would defer to the local command, if they felt there was a need to they could override it. There is no indication yet it occurred at the school this week.
            When US Border Patrol agents who belong to the specialized unit responded to the school around 12:15 p.m., the officer in charge had already made the determination it was a barricaded subject situation, according to a source familiar with the situation.
            "They showed up from where they were and put together the operation hastily," the source added. "Some of the officers came from the field ... and some who were off duty also sped in to respond."