A picture of the hat worn by the elite, veteran BORTAC Border Patrol agent who killed the Uvalde school shooter reveals just how close the agent himself came to death.

A photo obtained by Fox News' Bill Melugin shows the hat with a major hole ripped into the mesh section at the very top. 

Border Patrol Agent's Hat Texas School Shooting

A cap worn by a Border Patrol agent is torn after being struck by a bullet as authorities engaged a gunman who killed 21 people inside a Uvalde, Texas, elementary school on Tuesday. (Customs and Border Patrol)

The bullet that made the hole also grazed the agent's head. Melugin reports that the elite BORTAC Border Patrol agent was wearing the hat when he, along with a tactical team, engaged the shooter who had barricaded himself in a classroom at Robb Elementary School.

The agent killed the gunman, identified as 18-year-old Salvador Ramos, in an exchange of gunfire.

TEXAS SCHOOL SHOOTING: LIVE UPDATES

Uvalde Robb Elementary school shooting

A view from the makeshift memorial in front of Robb Elementary School in Uvalde, Texas, on May 25, 2022. (Photo by Yasin Ozturk/Anadolu Agency via Getty Images)

A total of 21 people were killed in the attack, including 19 children and two teachers.

U.S. Customs and Border Protection sources told Fox News that the veteran agent is assigned to the Del Rio Sector in South Texas.

MOTHER OF TEXAS SCHOOL SHOOTER WAS IN DISBELIEF ABOUT SON SHOOTING GRANDMOTHER, BOYFRIEND'S MOM SAYS

People leave Uvalde Civic Center

People leave the Uvalde Civic Center following a shooting earlier in the day at Robb Elementary School, Tuesday, May 24, 2022, in Uvalde, Texas.  (William Luther/The San Antonio Express-News via AP)

CLICK HERE TO GET THE FOX NEWS APP 

Many of the agents based in Uvalde, which sits near the U.S.-Mexico border, have children who attend the school. 

Fox News' Bill Melugin and Louis Casiano contributed to this report.