A Capitol Police officer carries an equipment bag out of the first base dugout after the shooting at a congressional baseball practice in Alexandria on Wednesday. (John McDonnell/The Washington Post)

The U.S. Capitol Police officers who disrupted Wednesday’s shooting at a congressional baseball practice are being lauded as heroes for confronting the gunman even as two of them were injured in the barrage of gunfire.

Their quick response in protecting lawmakers is exactly what the force is tasked to do.

“The Mission of the USCP is to protect the Congress — its Members, employees, visitors and facilities — so it can fulfill its constitutional and legislative responsibilities in a safe, secure and open environment,” the police department says on its website.

Three Capitol Police officers were at the Alexandria ballpark during the shooting early Wednesday: Crystal Griner, David Bailey and Henry Cabrera. All were special agents and were part of House Majority Whip Steve Scalise’s security detail.

After an Illinois man, James T. Hodgkinson, began to spray the field with bullets, at least two of the officers returned fire.

(Monica Akhtar/The Washington Post)

Hodgkinson died after the shootout. Scalise (R-La.) was hospitalized in critical condition. Griner was shot in the ankle, and Bailey was struck by shrapnel.

A Hill staffer and a lobbyist also were wounded.

“Many lives would have been lost if not for the heroic actions of the two Capitol Police officers who took down the gunman despite sustaining gunshot wounds during a very, very brutal assault,” President Trump said Wednesday afternoon.

The history of the force dates to the early 1800s, when a lone officer, John Golding, was hired to keep watch over the Capitol after Congress moved from Philadelphia to Washington, according to a history of the department.

Congress officially approved the creation of a police force to protect the Capitol in 1828 after a series of security concerns emerged the previous year.

The new force was small: four officers who worked 15-hour shifts when Congress was in session. It grew and expanded over the years. The Sept. 11, 2001, attacks on the Pentagon and the World Trade Center spurred a huge leap, from about 800 officers to more than 1,700.

Capitol police armed with machine guns guard the Capitol on Wednesday after House Majority Whip Steve Scalise and others were shot and injured at an Alexandria ballfield earlier in the day. (Astrid Riecken/For The Washington Post)

Today, more than 2,100 officers and civilians work for the department, responding to issues such as suspicious packages, political protests and potential incidents of terrorism.

The force is also in charge of protecting the estimated 3 million to 5 million people from around the world who visit the Capitol grounds each year.

In 2013, the Capitol Police and Secret Service members fatally shot 34-year-old Miriam Carey on Capitol Hill after she led them on a car chase from the White House with her 13-month-old daughter in the back seat — a shooting that remains controversial.

In 2015, the Capitol Police arrested a man who landed a gyrocopter on the Capitol’s West Lawn in a political protest.

And in recent months in separate incidents, officers fired on a 20-year-old woman after she fled a traffic stop outside the Capitol grounds and arrested pro-marijuana activists who were handing out free joints near the Capitol.

Officers also are charged with providing protection to House and Senate leaders outside the Capitol grounds.

Without the Capitol Police officers there as part of Scalise’s detail Wednesday, other lawmakers said, the shooting that disrupted the GOP baseball team’s practice could have been much worse.

“The only chance we had was that shots were returned by the Capitol Police,” Sen. Rand Paul (R-Ky.), who was in a batting cage when he heard gunfire, said in an interview on Fox News.

Without the officers present, Paul said, the shooting would have been a “massacre.”

Since the force’s founding, four officers have died in the line of duty: Sgt. Christopher S. Eney, Officer Jacob J. Chestnut, Detective John M. Gibson and Sgt. Clinton J. Holtz.

Chestnut and Gibson were killed in 1998, after a man diagnosed as a paranoid schizophrenic went on a shooting rampage at the Capitol.