Flagrant foul
In basketball, a flagrant foul is a personal foul that involves excessive or violent contact that could injure the fouled player. A flagrant foul may be unintentional or purposeful; the latter type is also called an "intentional foul" in the National Basketball Association (NBA). However, not all intentional fouls are flagrant fouls, as it is an accepted strategy to intentionally commit a foul (without the intent to injure) in order to regain possession of the ball while minimizing how much time elapses on the game clock.

NBA
The National Basketball Association (NBA) established the flagrant foul to deter contact that, in addition to being against the rules, puts an opponent's safety or health at risk. When the flagrant foul was introduced in the 1990–91 season, the only penalty beyond that of a common personal foul was that the coach of the offended team could select which player would shoot the resulting free throw attempts. Starting with the 1990–91 season, the offended team also retains possession of the ball following a flagrant foul, in addition to receiving free throw attempts.The NBA defines two levels of flagrant fouls, flagrant foul—penalty (1) and flagrant foul—penalty (2). Flagrant 1 is "unnecessary contact committed by a player against an opponent", while the more serious Flagrant 2 is "unnecessary and excessive contact committed by a player against an opponent." Flagrant 2 results in an immediate ejection of the offender. Flagrant 1 does not result in the offender's ejection, unless the same player commits a second Flagrant 1 foul in the same game. Thus, Flagrant 1 and Flagrant 2 are analogous to the yellow card and red card used in various other sports. NBA referees have discretion in determining which level to call. Starting with the 2006–07 season, all Flagrant 2 fouls are reviewed via instant replay, and may be downgraded as a result of the review.Flagrant 2 fouls result in an automatic fine of the offending player. Additionally, the NBA has a "penalty points" system, whereby players committing a Flagrant 1 or Flagrant 2 are assessed one or two penalty points, respectively. During the regular season, accumulating more than five points results in an automatic suspension. During the NBA playoffs, suspensions of one or two games are meted out for every penalty point a player accrues above a total of three.

Game tactics
It is an accepted basketball strategy for a trailing team to commit fouls intentionally late in a game, in an attempt to regain possession of the ball while minimizing how much time elapses on the game clock. A common personal foul gives the fouling team a chance to regain possession of the ball by rebounding a missed free throw. Alternately, if the offended team makes both free throws, the fouling team will then be given possession of the ball, potentially giving them an opportunity to make a three-point field goal, which if made, yields a one-point gain to the fouling team.
In this context, the flagrant foul rule deters undesired, potentially injurious play by awarding possession of the ball to the offended team as an extra penalty. If the fouling team is judged to have committed a flagrant foul, the offended team retains possession of the ball following any free throw attempts. As there is no change in possession, there is no benefit to the team that committed the flagrant foul. Thus, teams that attempt a strategy of intentionally fouling must do so without having their fouls judged as flagrant.

FIBA
International Basketball Federation (FIBA) basketball rules have similar fouls but use different terms.

FIBA's unsportsmanlike foul is comparable to a Flagrant 1. Two in one game by the same player, or one unsportsmanlike and one technical foul result in automatic ejection of that player. Any of the following five criteria constitutes an unsportsmanlike foul:C1: The foul is not a legitimate attempt to directly play the ball within the spirit and intent of the rules.
C2: The foul is an excessive, hard contact caused by a player in an effort to play the ball or an opponent.
C3: There is an unnecessary contact caused by the defensive player in order to stop the progress of the offensive team in transition. This applies until the offensive player begins his act of shooting.
C4: There is a contact by the defensive player from behind or laterally on an opponent in an attempt to stop the fast break and there is no defensive player between the offensive player and the opponents’ basket. This applies until the offensive player begins his act of shooting.In addition, any foul by a defensive player before a throw-in during the last two minutes of the game was formerly penalized as an unsportsmanlike foul. This rule was changed in 2022, and these fouls are now penalized as a personal foul that incurs one free throw plus possession.
FIBA's disqualifying foul is comparable to a Flagrant 2 and results in immediate ejection of the offender. It is defined in the rulebook as any flagrant unsportsmanlike action by players, substitutes, head coaches, etc.The penalty for both unsportsmanlike and disqualifying fouls in full-court basketball is two free throws and a throw-in from the throw-in line in the team’s frontcourt.
In the halfcourt 3x3 variant, the penalty is also two free throws, but possession after the free throws varies based on the degree of the foul. After a player's first unsportsmanlike foul, possession goes to the team that was otherwise entitled to possession at the time of the play. Following any foul that results in ejection, possession goes to the non-offending team. The only exception is in the case of a double unsportsmanlike foul; no free throws are awarded in such a situation.

United States scholastic rules
U.S. college and high school rules define a flagrant foul as a personal or technical foul that is extreme or severe.

NCAA
The NCAA's Playing Rules Oversight Panel adopted the "flagrant" term before the 2011-12 season for both men's and women's basketball. However, the NCAA's women's rules committee abandoned the term "flagrant", effective with the 2017–18 season, in favor of FIBA's "unsportsmanlike" and "disqualifying" terms. These fouls are counted as personal fouls and technical fouls.

A flagrant 1 foul (men's) or unsportsmanlike foul (women's) involves excessive or severe contact during a live ball, including especially when a player "swings an elbow and makes illegal, non-excessive contact with an opponent above the shoulders". This offense includes the former "intentional foul" of fouling an opposing player to prevent an easy breakaway score. In women's basketball only, the unsportsmanlike foul also includes contact dead-ball technical fouls. The penalty for a flagrant 1 or unsportsmanlike foul is two free throws and a throw-in for the opposing team at the out-of-bounds spot nearest the foul.
A flagrant 2 foul (men's) or disqualifying foul (women's) involves unsportsmanlike conduct that is extreme in nature, including "when a player swings an elbow excessively and makes contact above the shoulders", or excessive or severe contact during a dead ball (men only). Fighting is also a flagrant 2 or disqualifying foul. The penalty for a flagrant 2 or disqualifying foul is immediate ejection of the offender, plus two free throws and a throw-in for the opposing team at the division line opposite the scorer's table.Certain conduct constitutes a flagrant foul despite not being malevolent or unsportsmanlike.

NFHS
In the United States, the NFHS rulebook, which governs high school play, defines flagrant fouls in Rule 10: Fouls and Penalties. The word "flagrant" itself is defined in Rule 2: Definitions; 2-16c calls it "a foul so severe or extreme that it places an opponent in danger of serious injury, and/or involves violations that are extremely or persistently vulgar or abusive conduct." All flagrant fouls result in disqualification of the offender in addition to two free throws and possession for the offended team.

Equivalents in other sports
In American football, such fouls generally result in a personal foul, such as unnecessary roughness, or an unsportsmanlike conduct penalty, and possibly immediate disqualification.
In association football, such fouls generally result in either a yellow card or a red card being issued.
In ice hockey, such fouls sometimes result in a boarding, attempt to injure or other infraction being called and may result in either a major or game misconduct, or match penalty.

References
Related reading
NCAA Rule 4: Definitions
NCAA Rule 10: Fouls and Penalties in 2008 NCAA Men's and Women's Basketball Rules
NFHS Rule 2: Definitions 2-16c
NFHS Rule 10: Fouls and Penalties
Kermit Washington, subject (along with Rudy Tomjanovich) of a book: John Feinstein (2002). The Punch: One Night, Two Lives, and the Fight That Changed Basketball Forever. Boston: Little, Brown, and Co. ISBN 0316279722.