The origin of the brachiopods is uncertain; they either arose from reduction of a multi-plated tubular organism, or from the folding of a slug-like organism with a protective shell on either end.  Since their Cambrian origin, the phylum rose to a Palaeozoic dominance, but dwindled during the Mesozoic.

Origins

Brachiopod fold hypothesis 

The long-standing hypothesis of brachiopod origins, which has recently come under fire, suggests that the brachiopods arose by the folding of a Halkieria-like organism, which bore two protective shells at either end of a scaled body.  The tannuolinids were thought to represent an intermediate form, although the fact that they do not, as thought, possess a scleritome means that this is now considered unlikely. Under this hypothesis, the Phoronid worms share a similar evolutionary history; molecular data also appear to indicate their membership of Brachiopoda.

Under the Brachiopod Fold Hypothesis, the "dorsal" and "ventral" valves would in fact represent an anterior and posterior shell. This would make the axes of symmetry consistent with that of other bilaterian phyla and appears to be consistent with the embryological development, in which the body axis folds to bring the shells from the dorsal surface to their mature position.  Further support has been identified from the gene expression pattern during development, but on balance, developmental evidence speaks against the BFH.

More recent developmental studies have cast doubt on the BFH.  Most significantly, the dorsal and ventral valves have significantly different origins; the dorsal (branchial) valve is secreted by dorsal epithelia, whereas the ventral (pedicle) valve corresponds to the cuticle of the pedicle, which becomes mineralized during development.  Moreover, the dorsal and ventral valves of Lingula do not display the Hox gene expression patterns that would be expected if they were ancestrally 'anterior' and 'posterior'.

Tommotiids 

An alternative to the BFH suggests that brachiopods arose through the shortening of a tube-like organism consisting of many shell plates.  It is possible that they arose from within the tommotiid group in this fashion.
The more derived tommotiid Paterimitra has a pair of brachiopod-like shells at its rear, in just the arrangement one would expect of a brachiopod.
This is supported by the similarities in mineralogy between the Tommotiids and the earliest brachiopods.

Crown group 
The earliest unequivocal brachiopod fossils appeared in the early Cambrian Period. The oldest known brachiopod is Aldanotreta sunnaginensis from the lowest Tommotian Stage, early Cambrian of the Siberia was confidently identified as a paterinid linguliforms.

Mineralization 
The Lingiliformea brachiopods have apatite shells, which contrasts with the calcitic exoskeleta of the other two brachiopod subphyla.  This split occurred very early – the earliest brachiopod assemblages, from the Tommotian, already contain both apatite- and calcite-secreting organisms.  Since the minerals used to form exoskeleta rarely change,  one might expect these two forms to represent two discrete lineages – but in fact, early brachiopods used a wide range of techniques and materials in shell construction, drawing from phosphatic, calcitic and organic  building blocks, and sometimes employing all three.  Deducing the original method of mineralisation is tricky; however, it appears that the tommotiids – probably the closest stem group to the brachiopoda, assuming that the Brachiopod Fold Hypothesis is false – produced the same shell microstructre as the earliest known brachiopods.  Their shells had a relatively high concentration of phosphate and organic material, though this decreased over time.

Palaeozoic dominance 
Brachiopods are extremely common fossils throughout the Palaeozoic.
During the Ordovician and Silurian periods, brachiopods became adapted to life in most marine environments and became particularly numerous in shallow water habitats, in some cases forming whole banks in much the same way as bivalves (such as mussels) do today. In some places, large sections of limestone strata and reef deposits are composed largely of their shells.

The major shift came with the Permian extinction, as a result of the Mesozoic marine revolution. Before the extinction event, brachiopods were more numerous and diverse than bivalve mollusks. Afterwards, in the Mesozoic, their diversity and numbers were drastically reduced and they were largely replaced by bivalve molluscs. Molluscs continue to dominate today, and the remaining orders of brachiopods survive largely in fringe environments.

Mesozoic decline 
Throughout their long geological history, the brachiopods have gone through several major proliferations and diversifications, and have also suffered from major extinctions as well.

It has been suggested that the slow decline of the brachiopods over the last 100 million years or so is a direct result of the rise in diversity of filter-feeding bivalves, which have ousted the brachiopods from their former habitats; however, the bivalves have undergone a steady rise in diversity from the mid-Paleozoic onwards, and their abundance is unrelated to that of the brachiopods; further, many bivalves occupy niches (e.g. burrowing) which brachiopods never inhabited.

Alternative possibilities for their demise include the increasing disturbance of sediments by roving deposit feeders (including many burrowing bivalves); the increased intensity and variety of shell-crushing predation; or even chance demise – they were hard hit in the End-Permian extinction and may simply never have recovered.

See also 
 Taxonomy of the Brachiopoda

References 

Brachiopods